author | Patrick Einheber <patrick.einheber@oracle.com> |
Wed, 27 Apr 2016 14:55:10 -0700 | |
changeset 5860 | afd31ba91ee9 |
parent 4995 | ecffc6614cfa |
permissions | -rw-r--r-- |
4995
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
1 |
Split from BSD method and add getent hosts |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
2 |
Also don't try to run `host hostname` if the host command isn't available. |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
3 |
No upstream facter 2.x is dead and new bugs are not being accepted. |
5860
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
4 |
|
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
5 |
--- facter-2.4.6/lib/facter/ipaddress.rb.orig 2016-04-19 15:19:02.958338799 -0700 |
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
6 |
+++ facter-2.4.6/lib/facter/ipaddress.rb 2016-04-19 15:27:05.519845908 -0700 |
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
7 |
@@ -1,3 +1,7 @@ |
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
8 |
+####################################################################### |
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
9 |
+# Oracle has modified the originally distributed contents of this file. |
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
10 |
+####################################################################### |
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
11 |
+ |
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
12 |
# Fact: ipaddress |
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
13 |
# |
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
14 |
# Purpose: Return the main IP address for a host. |
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
15 |
@@ -64,7 +68,7 @@ |
4995
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
16 |
end |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
17 |
|
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
18 |
Facter.add(:ipaddress) do |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
19 |
- confine :kernel => %w{NetBSD SunOS} |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
20 |
+ confine :kernel => %w{NetBSD} |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
21 |
setcode do |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
22 |
ip = nil |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
23 |
output = Facter::Util::IP.exec_ifconfig(["-a"]) |
5860
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
24 |
@@ -84,6 +88,41 @@ |
4995
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
25 |
end |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
26 |
|
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
27 |
Facter.add(:ipaddress) do |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
28 |
+ confine :osfamily => %w{Solaris} |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
29 |
+ setcode do |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
30 |
+ ip = nil |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
31 |
+ output = Facter::Util::IP.exec_ifconfig(["-a"]) |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
32 |
+ |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
33 |
+ output.each_line { |str| |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
34 |
+ if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
35 |
+ tmp = $1 |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
36 |
+ unless tmp =~ /^127\./ or tmp == "0.0.0.0" |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
37 |
+ ip = tmp |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
38 |
+ break |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
39 |
+ end |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
40 |
+ end |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
41 |
+ } |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
42 |
+ |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
43 |
+ # If we didn't get an IP from ifconfig see if we can get one from |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
44 |
+ # the hosts database |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
45 |
+ if ip.nil? && hostname = Facter.value(:hostname) |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
46 |
+ # we need Hostname to exist for this to work |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
47 |
+ host = nil |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
48 |
+ Facter::Core::Execution.execute("getent hosts #{hostname}").each_line { |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
49 |
+ |l| |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
50 |
+ _ip = l.chomp.split()[0] |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
51 |
+ if _ip !~ /^127\./ && _ip =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
52 |
+ ip = _ip |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
53 |
+ break |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
54 |
+ end |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
55 |
+ } |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
56 |
+ end |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
57 |
+ |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
58 |
+ ip |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
59 |
+ end |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
60 |
+end |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
61 |
+ |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
62 |
+Facter.add(:ipaddress) do |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
63 |
confine :kernel => %w{AIX} |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
64 |
setcode do |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
65 |
ip = nil |
5860
afd31ba91ee9
23146903 Puppet and OpenStack modules need modification notices
Patrick Einheber <patrick.einheber@oracle.com>
parents:
4995
diff
changeset
|
66 |
@@ -150,8 +189,9 @@ |
4995
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
67 |
|
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
68 |
Facter.add(:ipaddress, :timeout => 2) do |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
69 |
setcode do |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
70 |
- if hostname = Facter.value(:hostname) |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
71 |
- # we need Hostname to exist for this to work |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
72 |
+ if hostname = Facter.value(:hostname) && |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
73 |
+ Facter::Core::Execution.which('host') |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
74 |
+ # we need Hostname and `host` to exist for this to work |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
75 |
host = nil |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
76 |
if host = Facter::Core::Execution.execute("host #{hostname}") |
ecffc6614cfa
18631785 puppet command should be part of Puppet Management profile
Patrick Einheber <patrick.einheber@oracle.com>
parents:
diff
changeset
|
77 |
list = host.chomp.split(/\s/) |