summaryrefslogtreecommitdiffstats
path: root/lib/facter/ipaddress.rb
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2009-03-17 23:52:11 +1100
committerJames Turnbull <james@lovedthanlost.net>2009-03-17 23:52:11 +1100
commit1288b26e35a2a9e126d4ae260f377d854b3c3848 (patch)
tree18d0a092e9195fd6ec2397948242c7e631ede311 /lib/facter/ipaddress.rb
parenta6d6ba5454a805cf95a7aa4def0c12afc180b958 (diff)
downloadfacter-1288b26e35a2a9e126d4ae260f377d854b3c3848.tar.gz
facter-1288b26e35a2a9e126d4ae260f377d854b3c3848.tar.xz
facter-1288b26e35a2a9e126d4ae260f377d854b3c3848.zip
Fixed #2080 - IPAddress resolutions should be reordered
Diffstat (limited to 'lib/facter/ipaddress.rb')
-rw-r--r--lib/facter/ipaddress.rb82
1 files changed, 41 insertions, 41 deletions
diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb
index d7496f0..4c0bfe4 100644
--- a/lib/facter/ipaddress.rb
+++ b/lib/facter/ipaddress.rb
@@ -1,44 +1,3 @@
-Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
- setcode do
- require 'resolv'
-
- begin
- if hostname = Facter.value(:hostname)
- ip = Resolv.getaddress(hostname)
- unless ip == "127.0.0.1"
- ip
- end
- else
- nil
- end
- rescue Resolv::ResolvError
- nil
- rescue NoMethodError # i think this is a bug in resolv.rb?
- nil
- end
- end
-end
-
-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}")
- list = host.chomp.split(/\s/)
- if defined? list[-1] and
- list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
- list[-1]
- end
- else
- nil
- end
- else
- nil
- end
- end
-end
-
Facter.add(:ipaddress) do
confine :kernel => :linux
setcode do
@@ -168,3 +127,44 @@ Facter.add(:ipaddress) do
ip
end
end
+
+Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
+ setcode do
+ require 'resolv'
+
+ begin
+ if hostname = Facter.value(:hostname)
+ ip = Resolv.getaddress(hostname)
+ unless ip == "127.0.0.1"
+ ip
+ end
+ else
+ nil
+ end
+ rescue Resolv::ResolvError
+ nil
+ rescue NoMethodError # i think this is a bug in resolv.rb?
+ nil
+ end
+ end
+end
+
+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}")
+ list = host.chomp.split(/\s/)
+ if defined? list[-1] and
+ list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
+ list[-1]
+ end
+ else
+ nil
+ end
+ else
+ nil
+ end
+ end
+end