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?
How do I get the ipaddress of a provisioned machine via chef provisioning
333 Views Asked by Jason Thompson At
2
There are 2 best solutions below
0

The short answer is: you don't which is one reason you shouldn't be using chef-provisioning. Long answer, some of the drivers allow accessing the underlying object through the resource but what you'll end up with looks nothing like normal Chef code. Store each machine
object in an array and then later you can try to use that for a second pass on things.
The real answer is that the provisioning layer shouldn't be doing this, use something like Chef Search or the relevant cloud API from the recipe on the actual provisioned nodes like you would with "normal" Chef.
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 resourcehostsfile_entry
, something similar to:Assuming there that you have in a hash the list of IPs and hostnames from the databag.
Hope you found this helpful.