4993N/ASplit from BSD method and add getent hosts
4993N/AAlso don't try to run `host hostname` if the host command isn't available.
4993N/ANo upstream facter 2.x is dead and new bugs are not being accepted.
5858N/A
5858N/A--- facter-2.4.6/lib/facter/ipaddress.rb.orig 2016-04-19 15:19:02.958338799 -0700
5858N/A+++ facter-2.4.6/lib/facter/ipaddress.rb 2016-04-19 15:27:05.519845908 -0700
5858N/A@@ -1,3 +1,7 @@
5858N/A+#######################################################################
5858N/A+# Oracle has modified the originally distributed contents of this file.
5858N/A+#######################################################################
5858N/A+
5858N/A # Fact: ipaddress
5858N/A #
5858N/A # Purpose: Return the main IP address for a host.
5858N/A@@ -64,7 +68,7 @@
4993N/A end
4993N/A
4993N/A Facter.add(:ipaddress) do
4993N/A- confine :kernel => %w{NetBSD SunOS}
4993N/A+ confine :kernel => %w{NetBSD}
4993N/A setcode do
4993N/A ip = nil
4993N/A output = Facter::Util::IP.exec_ifconfig(["-a"])
5858N/A@@ -84,6 +88,41 @@
4993N/A end
4993N/A
4993N/A Facter.add(:ipaddress) do
4993N/A+ confine :osfamily => %w{Solaris}
4993N/A+ setcode do
4993N/A+ ip = nil
4993N/A+ output = Facter::Util::IP.exec_ifconfig(["-a"])
4993N/A+
4993N/A+ output.each_line { |str|
4993N/A+ if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
4993N/A+ tmp = $1
4993N/A+ unless tmp =~ /^127\./ or tmp == "0.0.0.0"
4993N/A+ ip = tmp
4993N/A+ break
4993N/A+ end
4993N/A+ end
4993N/A+ }
4993N/A+
4993N/A+ # If we didn't get an IP from ifconfig see if we can get one from
4993N/A+ # the hosts database
4993N/A+ if ip.nil? && hostname = Facter.value(:hostname)
4993N/A+ # we need Hostname to exist for this to work
4993N/A+ host = nil
4993N/A+ Facter::Core::Execution.execute("getent hosts #{hostname}").each_line {
4993N/A+ |l|
4993N/A+ _ip = l.chomp.split()[0]
4993N/A+ if _ip !~ /^127\./ && _ip =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
4993N/A+ ip = _ip
4993N/A+ break
4993N/A+ end
4993N/A+ }
4993N/A+ end
4993N/A+
4993N/A+ ip
4993N/A+ end
4993N/A+end
4993N/A+
4993N/A+Facter.add(:ipaddress) do
4993N/A confine :kernel => %w{AIX}
4993N/A setcode do
4993N/A ip = nil
5858N/A@@ -150,8 +189,9 @@
4993N/A
4993N/A Facter.add(:ipaddress, :timeout => 2) do
4993N/A setcode do
4993N/A- if hostname = Facter.value(:hostname)
4993N/A- # we need Hostname to exist for this to work
4993N/A+ if hostname = Facter.value(:hostname) &&
4993N/A+ Facter::Core::Execution.which('host')
4993N/A+ # we need Hostname and `host` to exist for this to work
4993N/A host = nil
4993N/A if host = Facter::Core::Execution.execute("host #{hostname}")
4993N/A list = host.chomp.split(/\s/)