Top Level Namespace

Defined Under Namespace

Modules: Facter, Plist Classes: Array, Hash, Symbol

Instance Method Summary collapse

Instance Method Details

#get_address_after_token(output, token, return_first = false) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/facter/ipaddress6.rb', line 26

def get_address_after_token(output, token, return_first=false)
  ip = nil

  String(output).scan(/#{token}\s?((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match|
    match = match.first
    unless match =~ /fe80.*/ or match == "::1"
      ip = match
      break if return_first
    end
  end

  ip
end

#metadata(id = "") ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/facter/ec2.rb', line 4

def (id = "")
  open("http://169.254.169.254/2008-02-01/meta-data/#{id||=''}").read.
    split("\n").each do |o|
    key = "#{id}#{o.gsub(/\=.*$/, '/')}"
    if key[-1..-1] != '/'
      value = open("http://169.254.169.254/2008-02-01/meta-data/#{key}").read.
        split("\n")
      symbol = "ec2_#{key.gsub(/\-|\//, '_')}".to_sym
      Facter.add(symbol) { setcode { value.join(',') } }
    else
      (key)
    end
  end
rescue => details
  Facter.warn "Could not retrieve ec2 metadata: #{details.message}"
end

#nameObject

ssh.rb Facts related to SSH



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/facter/ssh.rb', line 14

{"SSHDSAKey" => { :file => "ssh_host_dsa_key.pub", :sshfprrtype => 2 },
 "SSHRSAKey" => { :file => "ssh_host_rsa_key.pub", :sshfprrtype => 1 },
 "SSHECDSAKey" => { :file => "ssh_host_ecdsa_key.pub", :sshfprrtype => 3 },
 "SSHED25519Key" => { :file => "ssh_host_ed25519_key.pub", :sshfprrtype => 4 } }.each do |name,key|

  Facter.add(name) do
    setcode do
      value = nil
      
      [ "/etc/ssh",
        "/usr/local/etc/ssh",
        "/etc",
        "/usr/local/etc",
        "/etc/opt/ssh",
      ].each do |dir|
      
        filepath = File.join(dir,key[:file])
      
        if FileTest.file?(filepath)
          begin
            value = File.read(filepath).chomp.split(/\s+/)[1]
            break
          rescue
            value = nil
          end
        end
      end
      
      value
    end
  end
  
  Facter.add('SSHFP_' + name[3..-4]) do
    setcode do
      ssh = Facter.fact(name).value
      value = nil
      
      if ssh && key[:sshfprrtype]
        begin
          require 'digest/sha1'
          require 'base64'
          digest = Base64.decode64(ssh)
          value = 'SSHFP ' + key[:sshfprrtype].to_s + ' 1 ' + Digest::SHA1.hexdigest(digest)
          begin
            require 'digest/sha2'
            value += "\nSSHFP " + key[:sshfprrtype].to_s + ' 2 ' + Digest::SHA256.hexdigest(digest)
          rescue
          end
        rescue
          value = nil
        end
      end
      
      value
    end
    
  end
  
end

#selinux_mount_pointObject

This supports the fact that the selinux mount point is not always in the same location – the selinux mount point is operating system specific.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/facter/selinux.rb', line 17

def selinux_mount_point
  path = "/selinux"
  if FileTest.exists?('/proc/self/mounts')
    # Centos 5 shows an error in which having ruby use File.read to read
    # /proc/self/mounts combined with the puppet agent run with --listen causes
    # a hang. Reading from other parts of /proc does not seem to cause this problem.
    # The work around is to read the file in another process.
    # -- andy Fri Aug 31 2012
    selinux_line = Facter::Core::Execution.exec('cat /proc/self/mounts').each_line.find { |line| line =~ /selinuxfs/ }
    if selinux_line
      path = selinux_line.split[1]
    end
  end
  path
end

#userdataObject



21
22
23
24
25
26
27
28
29
# File 'lib/facter/ec2.rb', line 21

def userdata()
  Facter.add(:ec2_userdata) do
    setcode do
      if userdata = Facter::Util::EC2.userdata
        userdata.split
      end
    end
  end
end

#virtualObject

virtual fact specific to Google Compute Engine’s Linux sysfs entry.



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/facter/virtual.rb', line 209

Facter.add("virtual") do
  has_weight 500

  setcode do
    if output = Facter::Util::Virtual.virt_what
      case output
      when 'linux_vserver'
        Facter::Util::Virtual.vserver_type
      when /xen-hvm/i
        'xenhvm'
      when /xen-dom0/i
        'xen0'
      when /xen-domU/i
        'xenu'
      when /ibm_systemz/i
        'zlinux'
      else
        output.to_s.split("\n").last
      end
    end
  end
end