lib/facter/ipaddress.rb in facter-1.5 vs lib/facter/ipaddress.rb in facter-1.5.2
- old
+ new
@@ -1,6 +1,6 @@
-Facter.add(:ipaddress, :ldapname => "iphostnumber") do
+Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
setcode do
require 'resolv'
begin
if hostname = Facter.value(:hostname)
@@ -17,11 +17,11 @@
nil
end
end
end
-Facter.add(:ipaddress) do
+Facter.add(:ipaddress, :timeout => 2) 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}")
@@ -144,8 +144,27 @@
break
end
end
}
+ ip
+ end
+end
+
+Facter.add(:ipaddress) do
+ confine :kernel => %w{windows}
+ setcode do
+ ip = nil
+ output = %x{ipconfig}
+
+ output.split(/^\S/).each { |str|
+ if str =~ /IP Address.*: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
+ tmp = $1
+ unless tmp =~ /127\./
+ ip = tmp
+ break
+ end
+ end
+ }
ip
end
end