summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/facter.rb32
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/facter.rb b/lib/facter.rb
index 6d95ce9..fe0b684 100644
--- a/lib/facter.rb
+++ b/lib/facter.rb
@@ -938,7 +938,7 @@ class Facter
end
end
Facter.add("IPAddress") do
- confine :kernel => %w{FreeBSD NetBSD OpenBSD solaris darwin}
+ confine :kernel => %w{FreeBSD NetBSD OpenBSD solaris}
setcode do
ip = nil
output = %x{/sbin/ifconfig}
@@ -956,6 +956,36 @@ class Facter
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