I have few nodes in running mode, I have to set hostname to those nodes.
Is there any Cookbook, in that we can set attribute host_name and run that recipe on respective nodes?
This answer is over 6 years old.
As @lamont points out chef now supports a hostname resources
There is a community hostname cookbook.
NOTE: there is now a hostname resource in the chef-client itself that was based on the chef_hostname cookbook in this answer, which is what everyone should use
I just released an initial version of a chef_hostname cookbook:
https://supermarket.chef.io/cookbooks/chef_hostname
To use it declare that you depend on it in your metadata.rb:
depends "chef_hostname"
And then in you recipe code just use the hostname
resource that it provides to set the hostname:
hostname "foo.example.com"
Or set the hostname to the node.name:
hostname node.name
Or set to any attribute that you care you use:
hostname node["set_fqdn"]
This cookbook solves many outstanding issues. Including all the Issues and PRs that are open against the hostname cookbook:
Checkout my updated fork of the hostname cookbook that fixes a bug in hostname where the domain name gets appended twice to the FQDN.
Also, this fork allows you to set the ip to node["ipaddress"] instead of the default 127.0.1.1 or some other static ip.
https://github.com/nathantsoi/chef-cookbook-hostname
or
https://supermarket.getchef.com/cookbooks/hostnames
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With