Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Created June 22, 2011 19:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jtimberman/1040853 to your computer and use it in GitHub Desktop.
Save jtimberman/1040853 to your computer and use it in GitHub Desktop.
Ohai plugin to return semantic reference attributes for network addresses
# This might not work on newer (than 0.10.6) versions of Chef.
# Thanks for pointing to my new gist, spkane :)
# https://gist.github.com/1040543
require 'rubygems'
require 'ohai'
o = Ohai::System.new()
o.all_plugins
# And retrieve some useful semantic reference attributes for network interfaces
o['network']['interfaces'].each do |iface, addrs|
addrs['addresses'].each do |ip, params|
o["ipaddress_#{iface}"] = ip if params['family'].eql?('inet')
o["ipaddress6_#{iface}"] = ip if params['family'].eql?('inet6')
o["macaddress_#{iface}"] = ip if params['family'].eql?('lladdr')
end
end
@spkane
Copy link

spkane commented Feb 1, 2012

Just in case you stumble on this as I did, there is a more updated version of this that works in Chef 10.6 here:

https://gist.github.com/1040543

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment