How to install chef client on multiple nodes and registering them with chef server using cookbook?


Hello Professionals,

Am very new to chef and i have a scenario where i need to make 200+ nodes as chef clients and register them with the chef server, is there any cook book available to do this? Am looking to install chef client daemon on all my chef client nodes. Please help me and excuse me if am asking for basics here.



I asked this question of my instructor during chefconf. The answer I relieved is the best way of bootstrapping a large amount of nodes that are already built using to basically write a script with a for loop that connects to them in whatever way you would normally manage the OS. So for windows you would use powershell (winrm) and Linux you would use ssh. Simple script that just feeds in the server names, node names, run lists, roles, and environments is going to be your best course of action. We have this problem where I work and this is what we are planning to do for current machines, when newer machines are built we are going to have the orchestrator just bootstrap the nodes as part of the build process to eliminate this issue going forward.


Larryc, Your instructor has apparently never had to deal with autoscaling.

Partha, one of the most common approaches is to put, in whatever golden image you are deploying with, a registration key and an init script that ensures the fully qualified hostname is set consistently, installs chef-client, and uses a local copy of a "validation" key to register the client, then deletes the validation key and the init script. Because the key can register a host with Chef, it needs to be handled securely and

Sadly, that "fully qualified hostname" can get very confusing. Many Linux environments put the hostname into /etc/hosts as " myhost myhost.mydomain localhost.localdomain localhost" or something like that, And this causes the "hostname --fqdn" command to respond with "myhost", and under various configurations, that "myhost" will be the name Chef registers with. So cleaning up /etc/hosts into something sane is a critical, critical step. in setting up a new host.

You can make the script cuter and more idempotent, but there is a danger of spending too much time and re-registering the same host twice if you make a mistake. Ideally, installing these one-time-only setup scripts is laid on top of the golden image before you release it for deployment. The alternative is to build it into whatever tools you use to activate the hosts in the first place as part of a scripted operation.

Either way, you'll want to audit your deployed hosts for correct chef registration when done.


Sorry I read that wrong, I thought the servers already existed, i specifically asked my instructor about bootstrapping existing nodes since we have a large volume of them. we already have a method for bootstrapping new nodes using the orchestrator.


Thank you Larryc


Larryc, you are correct, i have existing nodes that i want to boot strap


I now, have the shell script below to get the knife running on all my 190 servers,

IP=`cat ip.txt`



NAME=`cat name.txt`

for ip in $IP; do

        knife bootstrap  $ip -ssh-port 22 --ssh-user $USER --sudo  --i $KEY --no-host-key-verify -N $NAME --run-list "role[webserver]"


exit $?

However, the problem i have is with the hostname, all my chef server do not have domain name registered on internet and it has only host name, like APAC101-Chef-Server. By my knife.rb has this name and my client nodes are not able to resolve this w/o adding IP in node's /etc/hosts file, It is not correct to do this for all 190 servers, i have is there any way to do this chef-server.rb, please help me


You would need to add a host file entry or get a dns record for it because SSL is required and it wont work with just an IP address. Where are you hosting your chef server that you cannot get a DNS record for it?