diff options
-rw-r--r-- | lib/facter/Cfkey.rb | 49 | ||||
-rw-r--r-- | lib/facter/architecture.rb | 26 | ||||
-rw-r--r-- | lib/facter/domain.rb | 118 | ||||
-rw-r--r-- | lib/facter/fqdn.rb | 18 | ||||
-rw-r--r-- | lib/facter/hardwareisa.rb | 8 | ||||
-rw-r--r-- | lib/facter/hardwaremodel.rb | 14 | ||||
-rw-r--r-- | lib/facter/hostname.rb | 44 | ||||
-rw-r--r-- | lib/facter/id.rb | 8 | ||||
-rw-r--r-- | lib/facter/ipaddress.rb | 270 | ||||
-rw-r--r-- | lib/facter/iphostnumber.rb | 32 | ||||
-rw-r--r-- | lib/facter/kernel.rb | 6 | ||||
-rw-r--r-- | lib/facter/kernelrelease.rb | 14 | ||||
-rw-r--r-- | lib/facter/lsb.rb | 27 | ||||
-rw-r--r-- | lib/facter/lsbmajdistrelease.rb | 3 | ||||
-rw-r--r-- | lib/facter/macaddress.rb | 120 | ||||
-rw-r--r-- | lib/facter/macosx.rb | 46 | ||||
-rw-r--r-- | lib/facter/operatingsystem.rb | 66 | ||||
-rw-r--r-- | lib/facter/operatingsystemrelease.rb | 100 | ||||
-rw-r--r-- | lib/facter/ps.rb | 14 | ||||
-rw-r--r-- | lib/facter/ssh.rb | 38 | ||||
-rw-r--r-- | lib/facter/uniqueid.rb | 8 |
21 files changed, 511 insertions, 518 deletions
diff --git a/lib/facter/Cfkey.rb b/lib/facter/Cfkey.rb index 794971b..4c17a0a 100644 --- a/lib/facter/Cfkey.rb +++ b/lib/facter/Cfkey.rb @@ -13,31 +13,30 @@ ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA ## - Facter.add(:Cfkey) do - setcode do - value = nil - ["/usr/local/etc/cfkey.pub", - "/etc/cfkey.pub", - "/var/cfng/keys/localhost.pub", - "/var/cfengine/ppkeys/localhost.pub", - "/var/lib/cfengine/ppkeys/localhost.pub", - "/var/lib/cfengine2/ppkeys/localhost.pub" - ].each { |file| - if FileTest.file?(file) - File.open(file) { |openfile| - value = openfile.readlines.reject { |line| - line =~ /PUBLIC KEY/ - }.collect { |line| - line.chomp - }.join("") - } - end - if value - break - end +Facter.add(:Cfkey) do + setcode do + value = nil + ["/usr/local/etc/cfkey.pub", + "/etc/cfkey.pub", + "/var/cfng/keys/localhost.pub", + "/var/cfengine/ppkeys/localhost.pub", + "/var/lib/cfengine/ppkeys/localhost.pub", + "/var/lib/cfengine2/ppkeys/localhost.pub" + ].each { |file| + if FileTest.file?(file) + File.open(file) { |openfile| + value = openfile.readlines.reject { |line| + line =~ /PUBLIC KEY/ + }.collect { |line| + line.chomp + }.join("") } - - value end - end + if value + break + end + } + value + end +end diff --git a/lib/facter/architecture.rb b/lib/facter/architecture.rb index 5db1834..3665a7f 100644 --- a/lib/facter/architecture.rb +++ b/lib/facter/architecture.rb @@ -1,14 +1,14 @@ - Facter.add(:architecture) do - confine :kernel => :linux - setcode do - model = Facter.value(:hardwaremodel) - case model - # most linuxen use "x86_64" - when 'x86_64': - Facter.value(:operatingsystem) == "Debian" ? "amd64" : model; - when /(i[3456]86|pentium)/: "i386" - else - model - end - end +Facter.add(:architecture) do + confine :kernel => :linux + setcode do + model = Facter.value(:hardwaremodel) + case model + # most linuxen use "x86_64" + when 'x86_64': + Facter.value(:operatingsystem) == "Debian" ? "amd64" : model; + when /(i[3456]86|pentium)/: "i386" + else + model end + end +end diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb index a4fa701..724dd1b 100644 --- a/lib/facter/domain.rb +++ b/lib/facter/domain.rb @@ -1,64 +1,64 @@ - Facter.add(:domain) do - setcode do - # First force the hostname to be checked - Facter.value(:hostname) +Facter.add(:domain) do + setcode do + # First force the hostname to be checked + Facter.value(:hostname) - # Now check to see if it set the domain - if defined? $domain and ! $domain.nil? - $domain - else - nil - end - end + # Now check to see if it set the domain + if defined? $domain and ! $domain.nil? + $domain + else + nil end - # Look for the DNS domain name command first. - Facter.add(:domain) do - setcode do - domain = Facter::Util::Resolution.exec('dnsdomainname') or nil - # make sure it's a real domain - if domain and domain =~ /.+\..+/ - domain - else - nil - end - end + end +end +# Look for the DNS domain name command first. +Facter.add(:domain) do + setcode do + domain = Facter::Util::Resolution.exec('dnsdomainname') or nil + # make sure it's a real domain + if domain and domain =~ /.+\..+/ + domain + else + nil end - Facter.add(:domain) do - setcode do - domain = Facter::Util::Resolution.exec('domainname') or nil - # make sure it's a real domain - if domain and domain =~ /.+\..+/ - domain - else - nil - end - end + end +end +Facter.add(:domain) do + setcode do + domain = Facter::Util::Resolution.exec('domainname') or nil + # make sure it's a real domain + if domain and domain =~ /.+\..+/ + domain + else + nil end - Facter.add(:domain) do - setcode do - value = nil - if FileTest.exists?("/etc/resolv.conf") - File.open("/etc/resolv.conf") { |file| - # is the domain set? - file.each { |line| - if line =~ /domain\s+(\S+)/ - value = $1 - break - end - } - } - ! value and File.open("/etc/resolv.conf") { |file| - # is the search path set? - file.each { |line| - if line =~ /search\s+(\S+)/ - value = $1 - break - end - } - } - value - else - nil - end - end + end +end +Facter.add(:domain) do + setcode do + value = nil + if FileTest.exists?("/etc/resolv.conf") + File.open("/etc/resolv.conf") { |file| + # is the domain set? + file.each { |line| + if line =~ /domain\s+(\S+)/ + value = $1 + break + end + } + } + ! value and File.open("/etc/resolv.conf") { |file| + # is the search path set? + file.each { |line| + if line =~ /search\s+(\S+)/ + value = $1 + break + end + } + } + value + else + nil end + end +end diff --git a/lib/facter/fqdn.rb b/lib/facter/fqdn.rb index 1a97401..1fcc764 100644 --- a/lib/facter/fqdn.rb +++ b/lib/facter/fqdn.rb @@ -1,10 +1,10 @@ - Facter.add(:fqdn) do setcode do - host = Facter.value(:hostname) - domain = Facter.value(:domain) - if host and domain - [host, domain].join(".") - else - nil - end - end +Facter.add(:fqdn) do setcode do + host = Facter.value(:hostname) + domain = Facter.value(:domain) + if host and domain + [host, domain].join(".") + else + nil end + end +end diff --git a/lib/facter/hardwareisa.rb b/lib/facter/hardwareisa.rb index 20d0e47..4dce535 100644 --- a/lib/facter/hardwareisa.rb +++ b/lib/facter/hardwareisa.rb @@ -1,4 +1,4 @@ - Facter.add(:hardwareisa) do - setcode 'uname -p', '/bin/sh' - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo FreeBSD OpenBSD NetBSD} - end +Facter.add(:hardwareisa) do + setcode 'uname -p', '/bin/sh' + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo FreeBSD OpenBSD NetBSD} +end diff --git a/lib/facter/hardwaremodel.rb b/lib/facter/hardwaremodel.rb index b69848d..2118ad4 100644 --- a/lib/facter/hardwaremodel.rb +++ b/lib/facter/hardwaremodel.rb @@ -1,8 +1,8 @@ - Facter.add(:hardwaremodel) do - setcode 'uname -m' - end +Facter.add(:hardwaremodel) do + setcode 'uname -m' +end - Facter.add(:hardwaremodel) do - confine :operatingsystem => :aix - setcode 'lsattr -El proc0 -a type|cut -f2 -d" "' - end +Facter.add(:hardwaremodel) do + confine :operatingsystem => :aix + setcode 'lsattr -El proc0 -a type|cut -f2 -d" "' +end diff --git a/lib/facter/hostname.rb b/lib/facter/hostname.rb index aec5f93..188efa4 100644 --- a/lib/facter/hostname.rb +++ b/lib/facter/hostname.rb @@ -1,25 +1,25 @@ - Facter.add(:hostname, :ldapname => "cn") do - setcode do - hostname = nil - name = Facter::Util::Resolution.exec('hostname') or nil - if name - if name =~ /^([\w-]+)\.(.+)$/ - hostname = $1 - # the Domain class uses this - $domain = $2 - else - hostname = name - end - hostname - else - nil - end +Facter.add(:hostname, :ldapname => "cn") do + setcode do + hostname = nil + name = Facter::Util::Resolution.exec('hostname') or nil + if name + if name =~ /^([\w-]+)\.(.+)$/ + hostname = $1 + # the Domain class uses this + $domain = $2 + else + hostname = name end + hostname + else + nil end + end +end - Facter.add(:hostname) do - confine :kernel => :darwin, :kernelrelease => "R7" - setcode do - %x{/usr/sbin/scutil --get LocalHostName} - end - end +Facter.add(:hostname) do + confine :kernel => :darwin, :kernelrelease => "R7" + setcode do + %x{/usr/sbin/scutil --get LocalHostName} + end +end diff --git a/lib/facter/id.rb b/lib/facter/id.rb index 99f822c..41db22f 100644 --- a/lib/facter/id.rb +++ b/lib/facter/id.rb @@ -1,4 +1,4 @@ - Facter.add(:id) do - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo AIX} - setcode "whoami" - end +Facter.add(:id) do + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo AIX} + setcode "whoami" +end diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb index cf80c0c..942c134 100644 --- a/lib/facter/ipaddress.rb +++ b/lib/facter/ipaddress.rb @@ -1,151 +1,151 @@ - Facter.add(:ipaddress, :ldapname => "iphostnumber") do - setcode do - require 'resolv' - - begin - if hostname = Facter.value(:hostname) - ip = Resolv.getaddress(hostname) - unless ip == "127.0.0.1" - ip - end - else - nil - end - rescue Resolv::ResolvError - nil - rescue NoMethodError # i think this is a bug in resolv.rb? - nil +Facter.add(:ipaddress, :ldapname => "iphostnumber") do + setcode do + require 'resolv' + + begin + if hostname = Facter.value(:hostname) + ip = Resolv.getaddress(hostname) + unless ip == "127.0.0.1" + ip end + else + nil end + rescue Resolv::ResolvError + nil + rescue NoMethodError # i think this is a bug in resolv.rb? + nil end - - Facter.add(:ipaddress) do - setcode do - if hostname = Facter.value(:hostname) - # we need Hostname to exist for this to work - host = nil - if host = Facter::Util::Resolution.exec("host #{hostname}") - host = host.chomp.split(/\s/) - if defined? list[-1] and - list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ - list[-1] - end - else - nil - end - else - nil + end +end + +Facter.add(:ipaddress) do + setcode do + if hostname = Facter.value(:hostname) + # we need Hostname to exist for this to work + host = nil + if host = Facter::Util::Resolution.exec("host #{hostname}") + host = host.chomp.split(/\s/) + if defined? list[-1] and + list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ + list[-1] end + else + nil end + else + nil end + end +end - Facter.add(:ipaddress) do - confine :kernel => :linux - setcode do - ip = nil - output = %x{/sbin/ifconfig} - - output.split(/^\S/).each { |str| - if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /127\./ - ip = tmp - break - end - end - } - - ip +Facter.add(:ipaddress) do + confine :kernel => :linux + setcode do + ip = nil + output = %x{/sbin/ifconfig} + + output.split(/^\S/).each { |str| + if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end end - end - - Facter.add(:ipaddress) do - confine :kernel => %w{FreeBSD OpenBSD solaris} - setcode do - ip = nil - output = %x{/sbin/ifconfig} - - output.split(/^\S/).each { |str| - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /127\./ - ip = tmp - break - end - end - } - - ip + } + + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{FreeBSD OpenBSD solaris} + setcode do + ip = nil + output = %x{/sbin/ifconfig} + + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end end - end + } - Facter.add(:ipaddress) do - confine :kernel => %w{NetBSD} - setcode do - ip = nil - output = %x{/sbin/ifconfig -a} - - output.split(/^\S/).each { |str| - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /127\./ - ip = tmp - break - end - end - } - - ip + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{NetBSD} + setcode do + ip = nil + output = %x{/sbin/ifconfig -a} + + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end end + } + + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{darwin} + setcode do + ip = nil + iface = "" + output = %x{/usr/sbin/netstat -rn} + if output =~ /^default\s*\S*\s*\S*\s*\S*\s*\S*\s*(\S*).*/ + iface = $1 + else + warn "Could not find a default route. Using first non-loopback interface" + end + if(iface != "") + output = %x{/sbin/ifconfig #{iface}} + else + output = %x{/sbin/ifconfig} end - Facter.add(:ipaddress) do - confine :kernel => %w{darwin} - setcode do - ip = nil - iface = "" - output = %x{/usr/sbin/netstat -rn} - if output =~ /^default\s*\S*\s*\S*\s*\S*\s*\S*\s*(\S*).*/ - iface = $1 - else - warn "Could not find a default route. Using first non-loopback interface" + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break end - if(iface != "") - output = %x{/sbin/ifconfig #{iface}} - else - output = %x{/sbin/ifconfig} - end - - output.split(/^\S/).each { |str| - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /127\./ - ip = tmp - break - end - end - } - - ip end - end - - Facter.add(:ipaddress) do - confine :kernel => %w{AIX} - setcode do - ip = nil - output = %x{/usr/sbin/ifconfig -a} - - output.split(/^\S/).each { |str| - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /127\./ - ip = tmp - break - end - end - } - - ip + } + + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{AIX} + setcode do + ip = nil + output = %x{/usr/sbin/ifconfig -a} + + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end end - end + } + + ip + end +end diff --git a/lib/facter/iphostnumber.rb b/lib/facter/iphostnumber.rb index 68b1c97..bc38432 100644 --- a/lib/facter/iphostnumber.rb +++ b/lib/facter/iphostnumber.rb @@ -1,18 +1,18 @@ - Facter.add(:iphostnumber) do - confine :kernel => :darwin, :kernelrelease => "R6" - setcode do - %x{/usr/sbin/scutil --get LocalHostName} - end - end - Facter.add(:iphostnumber) do - confine :kernel => :darwin, :kernelrelease => "R6" - setcode do - ether = nil - output = %x{/sbin/ifconfig} +Facter.add(:iphostnumber) do + confine :kernel => :darwin, :kernelrelease => "R6" + setcode do + %x{/usr/sbin/scutil --get LocalHostName} + end +end +Facter.add(:iphostnumber) do + confine :kernel => :darwin, :kernelrelease => "R6" + setcode do + ether = nil + output = %x{/sbin/ifconfig} - output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ - ether = $1 + output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ + ether = $1 - ether - end - end + ether + end +end diff --git a/lib/facter/kernel.rb b/lib/facter/kernel.rb index 4a453c3..01fe85b 100644 --- a/lib/facter/kernel.rb +++ b/lib/facter/kernel.rb @@ -1,3 +1,3 @@ - Facter.add(:kernel) do - setcode 'uname -s' - end +Facter.add(:kernel) do + setcode 'uname -s' +end diff --git a/lib/facter/kernelrelease.rb b/lib/facter/kernelrelease.rb index 652fd6a..0f8a643 100644 --- a/lib/facter/kernelrelease.rb +++ b/lib/facter/kernelrelease.rb @@ -1,8 +1,8 @@ - Facter.add(:kernelrelease) do - setcode 'uname -r' - end +Facter.add(:kernelrelease) do + setcode 'uname -r' +end - Facter.add(:kernelrelease, :timeout => 5) do - confine :kernel => :aix - setcode 'oslevel -s' - end +Facter.add(:kernelrelease, :timeout => 5) do + confine :kernel => :aix + setcode 'oslevel -s' +end diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb index 9d9dba8..6f6e4bf 100644 --- a/lib/facter/lsb.rb +++ b/lib/facter/lsb.rb @@ -19,20 +19,19 @@ "LSBDistDescription" => %r{^Description:\t(.*)$}, "LSBDistCodeName" => %r{^Codename:\t(.*)$} }.each do |fact, pattern| - - Facter.add(fact) do - setcode do - unless defined?(@@lsbdata) and defined?(@@lsbtime) and (Time.now.to_i - @@lsbtime.to_i < 5) - type = nil - @@lsbtime = Time.now - @@lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null') - end + Facter.add(fact) do + setcode do + unless defined?(@@lsbdata) and defined?(@@lsbtime) and (Time.now.to_i - @@lsbtime.to_i < 5) + type = nil + @@lsbtime = Time.now + @@lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null') + end - if pattern.match(@@lsbdata) - $1 - else - nil - end + if pattern.match(@@lsbdata) + $1 + else + nil + end + end end - end end diff --git a/lib/facter/lsbmajdistrelease.rb b/lib/facter/lsbmajdistrelease.rb index 94742db..44f3b9b 100644 --- a/lib/facter/lsbmajdistrelease.rb +++ b/lib/facter/lsbmajdistrelease.rb @@ -10,7 +10,6 @@ Facter.add("lsbmajdistrelease") do else result=Facter.value(:lsbdistrelease) end - result + result end end - diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb index f42f8a1..30d4b59 100644 --- a/lib/facter/macaddress.rb +++ b/lib/facter/macaddress.rb @@ -1,65 +1,65 @@ - Facter.add(:macaddress) do - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo} - setcode do - ether = [] - output = %x{/sbin/ifconfig -a} - output.each {|s| - ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/ - } - ether[0] - end - end - - Facter.add(:macaddress) do - confine :operatingsystem => %w{FreeBSD OpenBSD} - setcode do - ether = [] - output = %x{/sbin/ifconfig} - output.each {|s| - if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ - ether.push($1) - end - } - ether[0] - end - end +Facter.add(:macaddress) do + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo} + setcode do + ether = [] + output = %x{/sbin/ifconfig -a} + output.each {|s| + ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/ + } + ether[0] + end +end - Facter.add(:macaddress) do - confine :kernel => :darwin - setcode do - ether = nil - output = %x{/sbin/ifconfig} +Facter.add(:macaddress) do + confine :operatingsystem => %w{FreeBSD OpenBSD} + setcode do + ether = [] + output = %x{/sbin/ifconfig} + output.each {|s| + if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ + ether.push($1) + end + } + ether[0] + end +end - output.split(/^\S/).each { |str| - if str =~ /10baseT/ # we're wired - str =~ /ether (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ - ether = $1 - end - } +Facter.add(:macaddress) do + confine :kernel => :darwin + setcode do + ether = nil + output = %x{/sbin/ifconfig} - ether + output.split(/^\S/).each { |str| + if str =~ /10baseT/ # we're wired + str =~ /ether (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ + ether = $1 end - end - - Facter.add(:macaddress) do - confine :kernel => %w{AIX} - setcode do - ether = [] - ip = nil - output = %x{/usr/sbin/ifconfig -a} - output.each { |str| - if str =~ /([a-z]+\d+): flags=/ - devname = $1 - unless devname =~ /lo0/ - output2 = %x{/usr/bin/entstat #{devname}} - output2.each { |str2| - if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/ - ether.push($1) - end - } - end - end - } - ether[0] + } + + ether + end +end + +Facter.add(:macaddress) do + confine :kernel => %w{AIX} + setcode do + ether = [] + ip = nil + output = %x{/usr/sbin/ifconfig -a} + output.each { |str| + if str =~ /([a-z]+\d+): flags=/ + devname = $1 + unless devname =~ /lo0/ + output2 = %x{/usr/bin/entstat #{devname}} + output2.each { |str2| + if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/ + ether.push($1) + end + } + end end - end + } + ether[0] + end +end diff --git a/lib/facter/macosx.rb b/lib/facter/macosx.rb index 60bd1ad..e7573b0 100644 --- a/lib/facter/macosx.rb +++ b/lib/facter/macosx.rb @@ -10,11 +10,11 @@ # as published by the Free Software Foundation (version 2 of the License) # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # Jeff McCune # There's a lot more information coming out of system_profiler -xml @@ -25,30 +25,30 @@ require 'facter/util/macosx' if Facter.value(:kernel) == "Darwin" - Facter::Macosx.hardware_overview.each do |fact, value| - Facter.add("sp_#{fact}") do - confine :kernel => :darwin - setcode do - value.to_s - end + Facter::Macosx.hardware_overview.each do |fact, value| + Facter.add("sp_#{fact}") do + confine :kernel => :darwin + setcode do + value.to_s + end + end end - end - Facter::Macosx.os_overview.each do |fact, value| - Facter.add("sp_#{fact}") do - confine :kernel => :darwin - setcode do - value.to_s - end + Facter::Macosx.os_overview.each do |fact, value| + Facter.add("sp_#{fact}") do + confine :kernel => :darwin + setcode do + value.to_s + end + end end - end - Facter::Macosx.sw_vers.each do |fact, value| - Facter.add(fact) do - confine :kernel => :darwin - setcode do - value - end + Facter::Macosx.sw_vers.each do |fact, value| + Facter.add(fact) do + confine :kernel => :darwin + setcode do + value + end + end end - end end diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb index 6233aaa..d43da2d 100644 --- a/lib/facter/operatingsystem.rb +++ b/lib/facter/operatingsystem.rb @@ -1,37 +1,37 @@ - Facter.add(:operatingsystem) do - confine :kernel => :sunos - setcode do "Solaris" end - end +Facter.add(:operatingsystem) do + confine :kernel => :sunos + setcode do "Solaris" end +end - Facter.add(:operatingsystem) do - confine :kernel => :linux - setcode do - if Facter.value(:lsbdistid) == "Ubuntu" - "Ubuntu" - elsif FileTest.exists?("/etc/debian_version") - "Debian" - elsif FileTest.exists?("/etc/gentoo-release") - "Gentoo" - elsif FileTest.exists?("/etc/fedora-release") - "Fedora" - elsif FileTest.exists?("/etc/mandriva-release") - "Mandriva" - elsif FileTest.exists?("/etc/mandrake-release") - "Mandrake" - elsif FileTest.exists?("/etc/redhat-release") - txt = File.read("/etc/redhat-release") - if txt =~ /centos/i - "CentOS" - else - "RedHat" - end - elsif FileTest.exists?("/etc/SuSE-release") - "SuSE" - end +Facter.add(:operatingsystem) do + confine :kernel => :linux + setcode do + if Facter.value(:lsbdistid) == "Ubuntu" + "Ubuntu" + elsif FileTest.exists?("/etc/debian_version") + "Debian" + elsif FileTest.exists?("/etc/gentoo-release") + "Gentoo" + elsif FileTest.exists?("/etc/fedora-release") + "Fedora" + elsif FileTest.exists?("/etc/mandriva-release") + "Mandriva" + elsif FileTest.exists?("/etc/mandrake-release") + "Mandrake" + elsif FileTest.exists?("/etc/redhat-release") + txt = File.read("/etc/redhat-release") + if txt =~ /centos/i + "CentOS" + else + "RedHat" end + elsif FileTest.exists?("/etc/SuSE-release") + "SuSE" end + end +end - Facter.add(:operatingsystem) do - # Default to just returning the kernel as the operating system - setcode do Facter[:kernel].value end - end +Facter.add(:operatingsystem) do + # Default to just returning the kernel as the operating system + setcode do Facter[:kernel].value end +end diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/operatingsystemrelease.rb index 7991d6c..291b82c 100644 --- a/lib/facter/operatingsystemrelease.rb +++ b/lib/facter/operatingsystemrelease.rb @@ -1,61 +1,61 @@ - Facter.add(:operatingsystemrelease) do - confine :operatingsystem => :fedora - setcode do - File::open("/etc/fedora-release", "r") do |f| - line = f.readline.chomp - if line =~ /\(Rawhide\)$/ - "Rawhide" - elsif line =~ /release (\d+)/ - $1 - end - end +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => :fedora + setcode do + File::open("/etc/fedora-release", "r") do |f| + line = f.readline.chomp + if line =~ /\(Rawhide\)$/ + "Rawhide" + elsif line =~ /release (\d+)/ + $1 end end + end +end - Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{RedHat} - setcode do - File::open("/etc/redhat-release", "r") do |f| - line = f.readline.chomp - if line =~ /\(Rawhide\)$/ - "Rawhide" - elsif line =~ /release (\d+)/ - $1 - end - end +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => %w{RedHat} + setcode do + File::open("/etc/redhat-release", "r") do |f| + line = f.readline.chomp + if line =~ /\(Rawhide\)$/ + "Rawhide" + elsif line =~ /release (\d+)/ + $1 end end + end +end - Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{CentOS} - setcode do - release = Facter::Util::Resolution.exec('rpm -q centos-release') - if release =~ /release-(\d+)/ - $1 - end +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => %w{CentOS} + setcode do + release = Facter::Util::Resolution.exec('rpm -q centos-release') + if release =~ /release-(\d+)/ + $1 end - end + end +end - Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{Debian} - setcode do - release = Facter::Util::Resolution.exec('cat /proc/version') - if release =~ /\(Debian (\d+.\d+).\d+-\d+\)/ - $1 - end - end - end +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => %w{Debian} + setcode do + release = Facter::Util::Resolution.exec('cat /proc/version') + if release =~ /\(Debian (\d+.\d+).\d+-\d+\)/ + $1 + end + end +end - Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{Ubuntu} - setcode do - release = Facter::Util::Resolution.exec('cat /etc/issue') - if release =~ /Ubuntu (\d+.\d+)/ - $1 - end +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => %w{Ubuntu} + setcode do + release = Facter::Util::Resolution.exec('cat /etc/issue') + if release =~ /Ubuntu (\d+.\d+)/ + $1 end - end + end +end - Facter.add(:operatingsystemrelease) do - setcode do Facter[:kernelrelease].value end - end +Facter.add(:operatingsystemrelease) do + setcode do Facter[:kernelrelease].value end +end diff --git a/lib/facter/ps.rb b/lib/facter/ps.rb index fbf0c7f..23f238d 100644 --- a/lib/facter/ps.rb +++ b/lib/facter/ps.rb @@ -1,8 +1,8 @@ - Facter.add(:ps) do - setcode do 'ps -ef' end - end +Facter.add(:ps) do + setcode do 'ps -ef' end +end - Facter.add(:ps) do - confine :operatingsystem => %w{FreeBSD NetBSD OpenBSD Darwin} - setcode do 'ps -auxwww' end - end +Facter.add(:ps) do + confine :operatingsystem => %w{FreeBSD NetBSD OpenBSD Darwin} + setcode do 'ps -auxwww' end +end diff --git a/lib/facter/ssh.rb b/lib/facter/ssh.rb index 29ea67c..318e9d4 100644 --- a/lib/facter/ssh.rb +++ b/lib/facter/ssh.rb @@ -13,25 +13,21 @@ ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA ## - ["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each { |dir| - {"SSHDSAKey" => "ssh_host_dsa_key.pub", - "SSHRSAKey" => "ssh_host_rsa_key.pub"}.each { |name,file| - Facter.add(name) do - setcode do +["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each do |dir| + {"SSHDSAKey" => "ssh_host_dsa_key.pub", "SSHRSAKey" => "ssh_host_rsa_key.pub"}.each do |name,file| + Facter.add(name) do + setcode do + value = nil + filepath = File.join(dir,file) + if FileTest.file?(filepath) + begin + File.open(filepath) { |f| value = f.read.chomp.split(/\s+/)[1] } + rescue value = nil - filepath = File.join(dir,file) - if FileTest.file?(filepath) - begin - File.open(filepath) { |f| - value = f.read.chomp.split(/\s+/)[1] - } - rescue - value = nil - end - end - value - end # end of proc - end # end of add - } # end of hash each - } # end of dir each - + end + end + value + end # end of proc + end # end of add + end # end of hash each +end # end of dir each diff --git a/lib/facter/uniqueid.rb b/lib/facter/uniqueid.rb index 2eae3cc..d1553c5 100644 --- a/lib/facter/uniqueid.rb +++ b/lib/facter/uniqueid.rb @@ -1,4 +1,4 @@ - Facter.add(:uniqueid) do - setcode 'hostid', '/bin/sh' - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo AIX} - end +Facter.add(:uniqueid) do + setcode 'hostid', '/bin/sh' + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo AIX} +end |