X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=facts%2Fipaddresses.rb;h=05e3e9097a17435ef4324c672b562366302b603b;hb=e2c4a3c78ac6bd82c2096508501f5508b2ec96f5;hp=d03bbbc4ead3583fd90d311f02b83d6255a91039;hpb=08102df3baf78bb0f4b4d99410c5a93bb282f673;p=mirror%2Fdsa-puppet.git diff --git a/facts/ipaddresses.rb b/facts/ipaddresses.rb index d03bbbc4e..05e3e9097 100644 --- a/facts/ipaddresses.rb +++ b/facts/ipaddresses.rb @@ -1,26 +1,58 @@ 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{1,2} .*/ - 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{1,3} .*/ - 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(",")