We use bonded interfaces on our production hardware.
But only on production hardware, staging and dev just use the ethX interfaces.
So we needed a way for chef to identify the public & private interfaces regardless of whether they are bonded or not.
To start with I pulled down the ohai cookbook and added a few scripts to the plugins directory.
Thats all there is.
The two plugins below identify the public and private interfaces as either being eth0 || bond0 & eth1 || bond1
provides "private_interface" cmd = '/sbin/ifconfig bond0' system(cmd) if $? == 0 private_interface "bond0" else private_interface "eth0" end
provides "public_interface" cmd = '/sbin/ifconfig bond1' system(cmd) if $? == 0 public_interface "bond1" else public_interface "eth1" end
From the chef ui you can see that public_interface and private_interface are now listed on the top level for a node.
This allows me to specify in a template/recipe to use the public or private interface, ohai automatically discovers what the interface actually is.
Example from a recipe for ufw:
firewall_rule "http-internal" do port 8098 action :allow interface node['private_interface'] notifies :enable, "firewall[ufw]" end