X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=facts%2Fipaddresses.rb;h=eddbe66d3ab670aeaf0b047e43225a92ce493395;hb=c6dc0370153b53656863ffbea8673d09f278bd82;hp=17dbd84aeb5f349001524fc1fdf28e2d50f27033;hpb=7ccfad99d929b3aa18be9f61bde472f4570ca1e0;p=mirror%2Fdsa-puppet.git diff --git a/facts/ipaddresses.rb b/facts/ipaddresses.rb index 17dbd84ae..eddbe66d3 100644 --- a/facts/ipaddresses.rb +++ b/facts/ipaddresses.rb @@ -1,26 +1,34 @@ 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("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(",")