[chef] Getting IP Addresses in Chef 0.8


Chronological Thread 
  • From: Bryan McLellan < >
  • To:
  • Subject: [chef] Getting IP Addresses in Chef 0.8
  • Date: Fri, 2 Jul 2010 02:11:54 +0000

In Chef 0.7 I would search the node index and collect relevant data like so:

munin_hosts = search(:node, "roles:optimize_server").map { |host| {
    "hostname" => host["hostname"],
    "fqdn" => host["fqdn"],
    "domain" => host["domain"],
    "ipaddress" => host["ipaddress"],
    "interfaces" => host["network"]["interfaces"]
  }
}

In Chef 0.8, I went to this:
munin_hosts = search(:node, "run_list:role\\[optimize_server\\]").map { 
|host| {
    "hostname" => host["hostname"],
    "fqdn" => host["fqdn"],
    "domain" => host["domain"],
    "ipaddress" => host["ipaddress"],
    "interfaces" => host["network"]["interfaces"]
  }
}

Now, in different circumstances I care about different IP addresses
which ohai rarely makes the default interface address. I would collect
addresses from individual interfaces like so:

ipaddress_raw = host["interfaces"]["tun0"]["addresses"].invert["inet"]

However I can't do that in Chef 0.8 because this is now a
Chef::Attribute and it has no invert method or a to_s method.

How do I get the IP address of a particular known interface name in Chef 
0.8.16?

Bryan


  • [chef] Getting IP Addresses in Chef 0.8, Bryan McLellan, 07/01/2010

Archive powered by MHonArc 2.6.16.

§