Guest User

Untitled

a guest
Apr 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. require 'facter'
  2.  
  3. alias_lines = `ip addr | grep secondary`.split("\n")
  4.  
  5. # facts will be will be an array of arrays in the form of ["10.10.41.113", "0", "3"]
  6. # where f[0] = ip, f[1] = interface, f[2] = alias
  7. ipdata = /^.*inet (.*)\/.*eth([0-9]+):([0-9]+)$/
  8. facts = alias_lines.map {|a| ipdata.match(a).captures}
  9.  
  10. facts.each do |f|
  11. Facter.add("ipaddress_eth#{f[1]}_#{f[2]}") do
  12. setcode {f[0]}
  13. end
  14.  
  15. #puts "ipaddress_eth#{f[1]}_#{f[2]} = " + Facter["ipaddress_eth#{f[1]}_#{f[2]}"].value
  16. end
Add Comment
Please, Sign In to add comment