X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=facts%2Fipaddresses.rb;h=05e3e9097a17435ef4324c672b562366302b603b;hb=e7c91b08cf909f011795f3d79f15e22b1e975d6c;hp=f1bbd6990fc401d6530b00db9b516c5713689c1d;hpb=e0ece8d7a60d196df7724434114795e59ddacf87;p=mirror%2Fdsa-puppet.git diff --git a/facts/ipaddresses.rb b/facts/ipaddresses.rb index f1bbd6990..05e3e9097 100644 --- a/facts/ipaddresses.rb +++ b/facts/ipaddresses.rb @@ -1,28 +1,66 @@ Facter.add("v4ips") do + confine :kernel => :linux addrs = [] - %x{ip addr list}.each do |line| - next unless line =~ /\s+inet/ - next if line =~ /scope (link|host)/ - if line =~ /\s+inet\s+(\S+)\/\d\d .*/ - addrs << $1 + if FileTest.exist?("/bin/ip") + %x{ip addr list}.each do |line| + next unless line =~ /\s+inet/ + next if line =~ /scope (link|host)/ + if line =~ /\s+inet\s+(\S+)\/\d{1,2} .*/ + addrs << $1 + end end end + ret = addrs.join(",") + if ret.empty? + ret = 'no' + end setcode do - addrs.join(",") + ret end end +Facter.add("v4ips") do + confine :kernel => 'GNU/kFreeBSD' + setcode do + addrs = [] + output = %x{/sbin/ifconfig} + + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + addrs << tmp + break + end + end + } + + ret = addrs.join(",") + if ret.empty? + ret = 'no' + end + ret + end +end + Facter.add("v6ips") do + confine :kernel => :linux addrs = [] - %x{ip addr list}.each do |line| - next unless line =~ /\s+inet/ - next if line =~ /scope (link|host)/ - if line =~ /\s+inet6\s+(\S+)\/\d\d .*/ - addrs << $1 + if FileTest.exist?("/bin/ip") + %x{ip addr list}.each do |line| + next unless line =~ /\s+inet/ + next if line =~ /scope (link|host)/ + if line =~ /\s+inet6\s+(\S+)\/\d{1,3} .*/ + addrs << $1 + end end end + ret = addrs.join(",") + if ret.empty? + ret = 'no' + end setcode do - addrs.join(",") + ret end end