summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2008-05-17 00:32:34 +1000
committerJames Turnbull <james@lovedthanlost.net>2008-05-17 00:32:34 +1000
commite02b0b386ed84384daeb2da0879bf215cfcfa2ef (patch)
tree36cdd5c3cc6143ce6faccb87ba6461bf5f481a29
parent9c91a6d3fb9da933d8e1ba4149ee1b5587e6b007 (diff)
downloadfacter-e02b0b386ed84384daeb2da0879bf215cfcfa2ef.tar.gz
facter-e02b0b386ed84384daeb2da0879bf215cfcfa2ef.tar.xz
facter-e02b0b386ed84384daeb2da0879bf215cfcfa2ef.zip
Updated version. Moved most facts to seperate files.
-rwxr-xr-xbin/facter4
-rw-r--r--lib/facter.rb2
-rw-r--r--lib/facter/Cfkey.rb (renamed from lib/facter/cfengine.rb)2
-rw-r--r--lib/facter/architecture.rb14
-rw-r--r--lib/facter/core.rb27
-rw-r--r--lib/facter/domain.rb64
-rw-r--r--lib/facter/facterversion.rb3
-rw-r--r--lib/facter/fqdn.rb10
-rw-r--r--lib/facter/hardwareisa.rb4
-rw-r--r--lib/facter/hardwaremodel.rb3
-rw-r--r--lib/facter/hostname.rb25
-rw-r--r--lib/facter/id.rb4
-rw-r--r--lib/facter/ipaddress.rb131
-rw-r--r--lib/facter/iphostnumber.rb18
-rw-r--r--lib/facter/ipmess.rb14
-rw-r--r--lib/facter/kernel.rb43
-rw-r--r--lib/facter/kernelrelease.rb3
-rw-r--r--lib/facter/macaddress.rb42
-rw-r--r--lib/facter/manufacturer.rb18
-rw-r--r--lib/facter/memory.rb13
-rw-r--r--lib/facter/netmask.rb25
-rw-r--r--lib/facter/networking.rb310
-rw-r--r--lib/facter/operatingsystem.rb37
-rw-r--r--lib/facter/operatingsystemrelease.rb61
-rw-r--r--lib/facter/os.rb115
-rw-r--r--lib/facter/process.rb29
-rw-r--r--lib/facter/processor.rb13
-rw-r--r--lib/facter/ps.rb8
-rw-r--r--lib/facter/puppetversion.rb10
-rw-r--r--lib/facter/rubysitedir.rb8
-rw-r--r--lib/facter/rubyversion.rb3
-rw-r--r--lib/facter/uniqueid.rb4
32 files changed, 469 insertions, 598 deletions
diff --git a/bin/facter b/bin/facter
index e9604ab..06d61ed 100755
--- a/bin/facter
+++ b/bin/facter
@@ -74,8 +74,8 @@ options = {
result.each { |opt,arg|
case opt
when "--version"
- puts "%s" % Facter.version
- exit
+ puts "%s" % Facter.version
+ exit
when "--yaml"
options[:yaml] = true
when "--debug"
diff --git a/lib/facter.rb b/lib/facter.rb
index 30f363d..aae3326 100644
--- a/lib/facter.rb
+++ b/lib/facter.rb
@@ -27,7 +27,7 @@ module Facter
include Comparable
include Enumerable
- FACTERVERSION = '1.3.8'
+ FACTERVERSION = '2.0.0'
# = Facter
# Functions as a hash of 'facts' you might care about about your
# system, such as mac address, IP address, Video card, etc.
diff --git a/lib/facter/cfengine.rb b/lib/facter/Cfkey.rb
index 6db24db..794971b 100644
--- a/lib/facter/cfengine.rb
+++ b/lib/facter/Cfkey.rb
@@ -1,4 +1,4 @@
-## cfengine.rb
+## Cfkey.rb
## Facts related to cfengine
##
## This program is free software; you can redistribute it and/or
diff --git a/lib/facter/architecture.rb b/lib/facter/architecture.rb
new file mode 100644
index 0000000..5db1834
--- /dev/null
+++ b/lib/facter/architecture.rb
@@ -0,0 +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
+ end
diff --git a/lib/facter/core.rb b/lib/facter/core.rb
deleted file mode 100644
index 0c5fdd5..0000000
--- a/lib/facter/core.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-Facter.add(:facterversion) do
- setcode { Facter::FACTERVERSION.to_s }
-end
-
-Facter.add(:rubyversion) do
- setcode { RUBY_VERSION.to_s }
-end
-
-Facter.add(:puppetversion) do
- setcode {
- begin
- require 'puppet'
- Puppet::PUPPETVERSION.to_s
- rescue LoadError
- nil
- end
- }
-end
-
-Facter.add :rubysitedir do
- setcode do
- version = RUBY_VERSION.to_s.sub(/\.\d+$/, '')
- $:.find do |dir|
- dir =~ /#{File.join("site_ruby", version)}$/
- end
- end
-end
diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb
new file mode 100644
index 0000000..a4fa701
--- /dev/null
+++ b/lib/facter/domain.rb
@@ -0,0 +1,64 @@
+ 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
+ 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
+ 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
+ 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/facterversion.rb b/lib/facter/facterversion.rb
new file mode 100644
index 0000000..0b1cfda
--- /dev/null
+++ b/lib/facter/facterversion.rb
@@ -0,0 +1,3 @@
+Facter.add(:facterversion) do
+ setcode { Facter::FACTERVERSION.to_s }
+end
diff --git a/lib/facter/fqdn.rb b/lib/facter/fqdn.rb
new file mode 100644
index 0000000..1a97401
--- /dev/null
+++ b/lib/facter/fqdn.rb
@@ -0,0 +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
+ end
diff --git a/lib/facter/hardwareisa.rb b/lib/facter/hardwareisa.rb
new file mode 100644
index 0000000..20d0e47
--- /dev/null
+++ b/lib/facter/hardwareisa.rb
@@ -0,0 +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
diff --git a/lib/facter/hardwaremodel.rb b/lib/facter/hardwaremodel.rb
new file mode 100644
index 0000000..8cc53f0
--- /dev/null
+++ b/lib/facter/hardwaremodel.rb
@@ -0,0 +1,3 @@
+ Facter.add(:hardwaremodel) do
+ setcode 'uname -m'
+ end
diff --git a/lib/facter/hostname.rb b/lib/facter/hostname.rb
new file mode 100644
index 0000000..aec5f93
--- /dev/null
+++ b/lib/facter/hostname.rb
@@ -0,0 +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
+ 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
new file mode 100644
index 0000000..e66745f
--- /dev/null
+++ b/lib/facter/id.rb
@@ -0,0 +1,4 @@
+ Facter.add(:id) do
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
+ setcode "whoami"
+ end
diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb
new file mode 100644
index 0000000..cd6dbcf
--- /dev/null
+++ b/lib/facter/ipaddress.rb
@@ -0,0 +1,131 @@
+ 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
+ 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
+ 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
+ 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
+
+ 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
diff --git a/lib/facter/iphostnumber.rb b/lib/facter/iphostnumber.rb
new file mode 100644
index 0000000..68b1c97
--- /dev/null
+++ b/lib/facter/iphostnumber.rb
@@ -0,0 +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}
+
+ output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
+ ether = $1
+
+ ether
+ end
+ end
diff --git a/lib/facter/ipmess.rb b/lib/facter/ipmess.rb
index 1e0c923..0ddc315 100644
--- a/lib/facter/ipmess.rb
+++ b/lib/facter/ipmess.rb
@@ -1,21 +1,9 @@
-#
# ipmess.rb
-# Try to get additional Facts about the machine's network interfaces on Linux
+# Try to get additional Facts about the machine's network interfaces
#
# Original concept Copyright (C) 2007 psychedelys <psychedelys@gmail.com>
# Update and *BSD support (C) 2007 James Turnbull <james@lovedthanlost.net>
#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# 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
-# 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
-#
require 'facter/util/ip'
diff --git a/lib/facter/kernel.rb b/lib/facter/kernel.rb
index 68f887a..4a453c3 100644
--- a/lib/facter/kernel.rb
+++ b/lib/facter/kernel.rb
@@ -1,46 +1,3 @@
-## kernel.rb
-## Facts related to the kernel, architecture and related
-##
-## This program is free software; you can redistribute it and/or
-## modify it under the terms of the GNU General Public License
-## 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
-## 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
-##
-
Facter.add(:kernel) do
setcode 'uname -s'
end
-
- Facter.add(:kernelrelease) do
- setcode 'uname -r'
- end
-
- Facter.add(:hardwaremodel) do
- setcode 'uname -m'
- 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
-
- 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/kernelrelease.rb b/lib/facter/kernelrelease.rb
new file mode 100644
index 0000000..9766ad9
--- /dev/null
+++ b/lib/facter/kernelrelease.rb
@@ -0,0 +1,3 @@
+ Facter.add(:kernelrelease) do
+ setcode 'uname -r'
+ end
diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb
new file mode 100644
index 0000000..647f39d
--- /dev/null
+++ b/lib/facter/macaddress.rb
@@ -0,0 +1,42 @@
+ 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 :kernel => :darwin
+ setcode do
+ ether = nil
+ output = %x{/sbin/ifconfig}
+
+ 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
+ }
+
+ ether
+ end
+ end
diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb
index 67ca569..0c74607 100644
--- a/lib/facter/manufacturer.rb
+++ b/lib/facter/manufacturer.rb
@@ -1,17 +1,7 @@
-## manufacturer.rb
-## Facts related to hardware manufacturer
-##
-## This program is free software; you can redistribute it and/or
-## modify it under the terms of the GNU General Public License
-## 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
-## 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
-##
+# manufacturer.rb
+# Facts related to hardware manufacturer
+#
+#
require 'facter/util/manufacturer'
diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb
index c507089..46fe859 100644
--- a/lib/facter/memory.rb
+++ b/lib/facter/memory.rb
@@ -1,21 +1,10 @@
-#
# memory.rb
# Additional Facts for memory/swap usage
#
# Copyright (C) 2006 Mooter Media Ltd
# Author: Matthew Palmer <matt@solutionsfirst.com.au>
#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# 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
-# 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
-
+#
require 'facter/util/memory'
{:MemorySize => "MemTotal",
diff --git a/lib/facter/netmask.rb b/lib/facter/netmask.rb
index 44a484a..140f8f1 100644
--- a/lib/facter/netmask.rb
+++ b/lib/facter/netmask.rb
@@ -1,21 +1,10 @@
-## netmask.rb
-## Find the netmask of the primary ipaddress
-## Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
-## Copyright (C) 2007 Mark 'phips' Phillips
-##
-## idea and originial source by Mark 'phips' Phillips
-##
-## This program is free software; you can redistribute it and/or
-## modify it under the terms of the GNU General Public License
-## 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
-## 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
-##
+# netmask.rb
+# Find the netmask of the primary ipaddress
+# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
+# Copyright (C) 2007 Mark 'phips' Phillips
+#
+# idea and originial source by Mark 'phips' Phillips
+#
def get_netmask
netmask = nil;
diff --git a/lib/facter/networking.rb b/lib/facter/networking.rb
deleted file mode 100644
index e4cf102..0000000
--- a/lib/facter/networking.rb
+++ /dev/null
@@ -1,310 +0,0 @@
-## networking.rb
-## Facts related to networking
-##
-## This program is free software; you can redistribute it and/or
-## modify it under the terms of the GNU General Public License
-## 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
-## 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
-##
-
- 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
- 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
- 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
- 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
- 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(:fqdn) do
- setcode do
- host = Facter.value(:hostname)
- domain = Facter.value(:domain)
- if host and domain
- [host, domain].join(".")
- else
- nil
- end
- end
- end
-
- 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
- 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(:uniqueid) do
- setcode 'hostid', '/bin/sh'
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
- 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 :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 :kernel => :darwin
- setcode do
- ether = nil
- output = %x{/sbin/ifconfig}
-
- 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
- }
-
- ether
- 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
- 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
- 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
-
- 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(:hostname) do
- confine :kernel => :darwin, :kernelrelease => "R7"
- setcode do
- %x{/usr/sbin/scutil --get LocalHostName}
- end
- end
- 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
-
- ether
- end
- end
-
diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb
new file mode 100644
index 0000000..6233aaa
--- /dev/null
+++ b/lib/facter/operatingsystem.rb
@@ -0,0 +1,37 @@
+ 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
+ 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
new file mode 100644
index 0000000..7991d6c
--- /dev/null
+++ b/lib/facter/operatingsystemrelease.rb
@@ -0,0 +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
+ 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
+ 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
+ end
+ end
+
+ Facter.add(:operatingsystemrelease) do
+ setcode do Facter[:kernelrelease].value end
+ end
diff --git a/lib/facter/os.rb b/lib/facter/os.rb
deleted file mode 100644
index 796df0d..0000000
--- a/lib/facter/os.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-## os.rb
-## Facts related to operating systems and releases
-##
-## This program is free software; you can redistribute it and/or
-## modify it under the terms of the GNU General Public License
-## 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
-## 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
-##
-
- 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
- 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(: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
- 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
- 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
- end
- end
-
- Facter.add(:operatingsystemrelease) do
- setcode do Facter[:kernelrelease].value end
- end
-
diff --git a/lib/facter/process.rb b/lib/facter/process.rb
deleted file mode 100644
index beeac47..0000000
--- a/lib/facter/process.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-## process.rb
-## Facts related to ps and processes
-##
-## This program is free software; you can redistribute it and/or
-## modify it under the terms of the GNU General Public License
-## 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
-## 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
-##
- 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(:id) do
- #confine :kernel => %w{Solaris Linux}
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
- setcode "whoami"
- end
-
diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb
index 069e06e..5e8e42e 100644
--- a/lib/facter/processor.rb
+++ b/lib/facter/processor.rb
@@ -1,22 +1,9 @@
-#
# processor.rb
# Additional Facts about the machine's CPUs
#
# Copyright (C) 2006 Mooter Media Ltd
# Author: Matthew Palmer <matt@solutionsfirst.com.au>
#
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# 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
-# 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
-#
require 'thread'
diff --git a/lib/facter/ps.rb b/lib/facter/ps.rb
new file mode 100644
index 0000000..fbf0c7f
--- /dev/null
+++ b/lib/facter/ps.rb
@@ -0,0 +1,8 @@
+ 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
diff --git a/lib/facter/puppetversion.rb b/lib/facter/puppetversion.rb
new file mode 100644
index 0000000..66fcfe8
--- /dev/null
+++ b/lib/facter/puppetversion.rb
@@ -0,0 +1,10 @@
+Facter.add(:puppetversion) do
+ setcode {
+ begin
+ require 'puppet'
+ Puppet::PUPPETVERSION.to_s
+ rescue LoadError
+ nil
+ end
+ }
+end
diff --git a/lib/facter/rubysitedir.rb b/lib/facter/rubysitedir.rb
new file mode 100644
index 0000000..c205322
--- /dev/null
+++ b/lib/facter/rubysitedir.rb
@@ -0,0 +1,8 @@
+Facter.add :rubysitedir do
+ setcode do
+ version = RUBY_VERSION.to_s.sub(/\.\d+$/, '')
+ $:.find do |dir|
+ dir =~ /#{File.join("site_ruby", version)}$/
+ end
+ end
+end
diff --git a/lib/facter/rubyversion.rb b/lib/facter/rubyversion.rb
new file mode 100644
index 0000000..48f5cc8
--- /dev/null
+++ b/lib/facter/rubyversion.rb
@@ -0,0 +1,3 @@
+Facter.add(:rubyversion) do
+ setcode { RUBY_VERSION.to_s }
+end
diff --git a/lib/facter/uniqueid.rb b/lib/facter/uniqueid.rb
new file mode 100644
index 0000000..b5726a0
--- /dev/null
+++ b/lib/facter/uniqueid.rb
@@ -0,0 +1,4 @@
+ Facter.add(:uniqueid) do
+ setcode 'hostid', '/bin/sh'
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
+ end