1 Split from BSD method and add getent hosts
2 Also don't try to run `host hostname` if the host command isn't available.
3 No upstream facter 2.x is dead and new bugs are not being accepted.
5 --- facter-2.4.6/lib/facter/ipaddress.rb.orig 2016-04-19 15:19:02.958338799 -0700
6 +++ facter-2.4.6/lib/facter/ipaddress.rb 2016-04-19 15:27:05.519845908 -0700
8 +#######################################################################
9 +# Oracle has modified the originally distributed contents of this file.
10 +#######################################################################
14 # Purpose: Return the main IP address for a host.
18 Facter.add(:ipaddress) do
19 - confine :kernel => %w{NetBSD SunOS}
20 + confine :kernel => %w{NetBSD}
23 output = Facter::Util::IP.exec_ifconfig(["-a"])
27 Facter.add(:ipaddress) do
28 + confine :osfamily => %w{Solaris}
31 + output = Facter::Util::IP.exec_ifconfig(["-a"])
33 + output.each_line { |str|
34 + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
36 + unless tmp =~ /^127\./ or tmp == "0.0.0.0"
43 + # If we didn't get an IP from ifconfig see if we can get one from
44 + # the hosts database
45 + if ip.nil? && hostname = Facter.value(:hostname)
46 + # we need Hostname to exist for this to work
48 + Facter::Core::Execution.execute("getent hosts #{hostname}").each_line {
50 + _ip = l.chomp.split()[0]
51 + if _ip !~ /^127\./ && _ip =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
62 +Facter.add(:ipaddress) do
63 confine :kernel => %w{AIX}
68 Facter.add(:ipaddress, :timeout => 2) do
70 - if hostname = Facter.value(:hostname)
71 - # we need Hostname to exist for this to work
72 + if hostname = Facter.value(:hostname) &&
73 + Facter::Core::Execution.which('host')
74 + # we need Hostname and `host` to exist for this to work
76 if host = Facter::Core::Execution.execute("host #{hostname}")
77 list = host.chomp.split(/\s/)