Please review pull request #182: Ticket/1.6.x/1346 facter i paddress opened by (ssvarma)
Description:
Added condition to look for ip, if not available then default to ifconfig on linux.
- Opened: Wed Feb 29 23:19:54 UTC 2012
- Based on: puppetlabs:master (a4f433e59653d0e0827744c7219d1c40aaabf0a2)
- Requested merge: ssvarma:ticket/1.6.x/1346-facterIPaddress (0046e34d5d57dcf75fc0bee06ecef9de57650582)
Diff follows:
diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb
index 360becd..a3d00ab 100644
--- a/lib/facter/ipaddress.rb
+++ b/lib/facter/ipaddress.rb
@@ -3,8 +3,12 @@
# Purpose: Return the main IP address for a host.
#
# Resolution:
-# On the Unixes does an ifconfig, and returns the first non 127.0.0.0/8
-# subnetted IP it finds.
+# On Linux, it looks to see if 'ip' is available and if so it does 'ip addr'
+# and returns the first non 127.0.0.0/8 subnet IP it finds. If 'ip' is not
+# available then it does a 'ifconfig' and returns the IP in the same way.
+#
+# On Unix, ifconfig returns the first non 127.0.0.0/8 subnet IP it finds.
+#
# On Windows, it attempts to use the socket library and resolve the machine's
# hostname via DNS.
#
@@ -26,8 +30,13 @@
confine :kernel => :linux
setcode do
ip = nil
- output = %x{/sbin/ifconfig}
+ if FileTest.exists?('/sbin/ip')
+ output = %x{/sbin/ip addr}
+ else
+ output = %x{/sbin/ifconfig}
+ end
+
output.split(/^\S/).each { |str|
if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
tmp = $1
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
