require 'facter' alias_lines = `ip addr | grep secondary`.split("\n") # facts will be will be an array of arrays in the form of ["10.10.41.113", "0", "3"] # where f[0] = ip, f[1] = interface, f[2] = alias ipdata = /^.*inet (.*)\/.*eth([0-9]+):([0-9]+)$/ facts = alias_lines.map {|a| ipdata.match(a).captures} facts.each do |f| Facter.add("ipaddress_eth#{f[1]}_#{f[2]}") do setcode {f[0]} end #puts "ipaddress_eth#{f[1]}_#{f[2]} = " + Facter["ipaddress_eth#{f[1]}_#{f[2]}"].value end