Ohai Plugin for OpenVZ VMs to get public IP Address

Media Temple uses the OpenVZ virtualization system and I have quite a few Media Temple servers under Chef management. The one thing that has made management difficult is that by default during a Chef run ohai returns as the default IP address which means I cannot run knife to execute commands from my workstation.

For example, when I run  knife node show mydv.server.com  I get the following:

Kinda sucks. If try to execute on all of my MT servers, say something like  knife ssh 'tags:mt' 'sudo chef-client'  I will get a ton of failed connection errors because it is trying to connect to

The solution is to get ohai to return the correct IP. OpenVZ has virtual interfaces and the actual public IP is assigned to them, while the main interface, eth0, is given the ip This ohai plugin will retrieve the correct IP.

Put this in your ohai plugins directory for chef: /etc/chef/plugins/openvz.rb and when chef runs, it will get the correct IP address.

Now when I run knife show mydb.server.com