How to get an array of all IP addresses on a node?

I’ve been using the following to get an array of all IP addresses on a node:
node.network.interfaces.map { |p, f| f[:addresses].keys }.flatten

Which I then clean up with the following to get rid of the mac addresses:
node.network.interfaces.map { |p, f| f[:addresses].keys
}.flatten.delete_if{|x| x =~ /(.):(.)/ }

It works on CentOS 5 hosts and vserver guests on CentOS 5 hosts however it
does not work on KVM guests or on RedHat 4 hosts. The output on those nodes
is different so they can’t use the “keys” method.
Anyone know of any reliable and consistent ways to get a list of all IP
Addresses on a node?

Thanks,
Chaim

Hello!

On Dec 20, 2011, at 5:51 AM, Chaim Keren-Tzion wrote:

It works on CentOS 5 hosts and vserver guests on CentOS 5 hosts however it does not work on KVM guests or on RedHat 4 hosts. The output on those nodes is different so they can't use the "keys" method.
Anyone know of any reliable and consistent ways to get a list of all IP Addresses on a node?

Try this:

That will create top-level attributes like "node['ipaddress_eth0']" when used in an Ohai plugin.

--
Opscode, Inc
Joshua Timberman, Technical Program Manager
IRC, Skype, Twitter, Github: jtimberman