1 From af1818469ed789bad373e6c0f8d29669acc39669 Mon Sep 17 00:00:00 2001
2 From: Don Penney <don.penney@windriver.com>
3 Date: Thu, 26 Oct 2017 10:44:20 -0400
4 Subject: [PATCH] Hardcode ipaddress fact to localhost
7 lib/facter/ipaddress.rb | 163 +-----------------------------------------------
8 1 file changed, 2 insertions(+), 161 deletions(-)
10 diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb
11 index 6179a4d..4c54791 100644
12 --- a/lib/facter/ipaddress.rb
13 +++ b/lib/facter/ipaddress.rb
17 -# Purpose: Return the main IP address for a host.
18 +# To avoid potential timeouts with this fact, just return 127.0.0.1 always
21 -# On the Unixes does an ifconfig, and returns the first non 127.0.0.0/8
22 -# subnetted IP it finds.
23 -# On Windows, it attempts to use the socket library and resolve the machine's
26 -# On LDAP based hosts it tries to use either the win32/resolv library to
27 -# resolve the hostname to an IP address, or on Unix, it uses the resolv
30 -# As a fall back for undefined systems, it tries to run the "host" command to
31 -# resolve the machine's hostname using the system DNS.
34 -# DNS resolution relies on working DNS infrastructure and resolvers on the
36 -# The ifconfig parsing purely takes the first IP address it finds without any
37 -# checking this is a useful IP address.
40 -require 'facter/util/ip'
42 -Facter.add(:ipaddress) do
43 - confine :kernel => :linux
46 - output = Facter::Util::IP.exec_ifconfig(["2>/dev/null"])
48 - regexp = /inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
49 - output.split("\n").each do |line|
50 - match = regexp.match(line)
51 - if match and not /^127\./.match(match[1])
61 -Facter.add(:ipaddress) do
62 - confine :kernel => %w{FreeBSD OpenBSD Darwin DragonFly}
65 - output = Facter::Util::IP.exec_ifconfig
67 - output.split(/^\S/).each do |str|
68 - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
70 - unless tmp =~ /^127\./
81 Facter.add(:ipaddress) do
82 - confine :kernel => %w{NetBSD SunOS}
85 - output = Facter::Util::IP.exec_ifconfig(["-a"])
87 - output.split(/^\S/).each do |str|
88 - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
90 - unless tmp =~ /^127\./ or tmp == "0.0.0.0"
101 -Facter.add(:ipaddress) do
102 - confine :kernel => %w{AIX}
106 - default_interface = Facter::Util::IP.exec_netstat(["-rn | grep default | awk '{ print $6 }'"])
107 - output = Facter::Util::IP.exec_ifconfig([default_interface])
109 - output.split(/^\S/).each do |str|
110 - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
119 -Facter.add(:ipaddress) do
120 - confine :kernel => %w{windows}
122 - require 'facter/util/ip/windows'
125 - adapters = Facter::Util::IP::Windows.get_preferred_ipv4_adapters
126 - adapters.find do |nic|
127 - nic.IPAddress.any? do |addr|
128 - ipaddr = addr if Facter::Util::IP::Windows.valid_ipv4_address?(addr)
137 -Facter.add(:ipaddress, :timeout => 2) do
139 - if Facter.value(:kernel) == 'windows'
140 - require 'win32/resolv'
146 - if hostname = Facter.value(:hostname)
147 - if Facter.value(:kernel) == 'windows'
148 - ip = Win32::Resolv.get_resolv_info.last[0]
150 - ip = Resolv.getaddress(hostname)
152 - unless ip == "127.0.0.1"
158 - rescue Resolv::ResolvError
160 - rescue NoMethodError # i think this is a bug in resolv.rb?
166 -Facter.add(:ipaddress, :timeout => 2) do
168 - if hostname = Facter.value(:hostname)
169 - # we need Hostname to exist for this to work
171 - if host = Facter::Core::Execution.execute("host #{hostname}")
172 - list = host.chomp.split(/\s/)
173 - if defined? list[-1] and
174 - list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/