Last Updated: February 25, 2016
· turtlebender

Ohai plugin to use eth1 on vagrant boxes

I often use vagrant multi-box setups. One issue is that if my chef recipes use the ipaddress attribute, I get the private ip address which won't allow my boxes to talk to each other.

To fix this I wrote a silly little ohai plugin:

provide "ipaddress"
require_plugin "#{os}::network"
network["interfaces"]["eth1"]["addresses"].each do |ip, params|
  if params['family'] == ('inet')
      ipaddress ip

Include this in your ohai cookbook as described here:


2 Responses
Add your response

Did you only distribute this on Vagrant installs, and skip it on production ones?

over 1 year ago ·

If you wrap the logic in if virtualization["system"] == "vbox" you can distribute this to your production environment without worries it'll execute.

over 1 year ago ·