chef-infrachef-provisioning

How do I get the ipaddress of a provisioned machine via chef provisioning


I am writing a chef provisioning recipe to provision a cluster of machines. I have more/less done that, but now I want to set the hosts file of all of the provisioned machines to be the dynamically assigned IP addresses of all of the other hosts. Is there a way to query what the ip address of a provisioned host is?


Solution

  • Not on ChefProvisioning layer, but I have done this as follows:

    You can use hostsfile cookbook from chef supermarket and a databag in chef server.

    It is possible to access to one node IP with attribute node[:ipaddress], store it inside the databag and then access with a loop through all ips, using hostsfile cookbook to create/update entries with resource hostsfile_entry, something similar to:

    node[:list_of_hosts].each do |name, ip|
      hostsfile_entry ip do
        hostname name
        action [:create_if_missing, :update]
      end
    end
    

    Assuming there that you have in a hash the list of IPs and hostnames from the databag.

    Hope you found this helpful.