Method to assign roles to all nodes simultaneously from chef server


Hi All,

I am new to CHEF and I am exploring the same. I have an environment where we have bulk of windows VMs. We use chef for configuration management. New VMs will be added to the pool on daily / weekly basis and hence we need to assign the newly added VMs to specific roles in chef to assign set of run list. Currently I do it manually from my workstation using " knife exec " toot. However I do not want to build a dependancy with my workstation for this. I would like to automate this task. Is the knife exec or similar tool is available in chef server as well, so that I can put a cron job on chef server to run this periodically. Or is there any other recommended solution to achieve this ?

I use below now from workstation. All VMs are in _default environment.

knife exec -E ‘nodes.find(“chef_environment:_default”) {|n| puts n.run_list << “role[vdi-desktops]” unless n.run_list.include?(“role[vdi-desktops]”); }’

Thanks and Regards,


You would generally handle this during the Chef bootstrap process via the first-run JSON (-j) command line argument. This allows nodes to set themselves up.


Hi Coderanger,

Thank you for your response !! I had a check on this. May I know if you are refering to what I have mentioned below ?

Populate /etc/chef/first-boot.json and run chef-client -j /etc/chef/first-boot.json

As I check I guess this has to be done during bootstrap process. Please correct me if my understanding is wrong.

Actually my scenario is slightly different. I have a VDI environment and the base image has the chef agent installed with the validator key and client.rb populated with proper details. All new VMs will be linked clone of this and hence the new VMs come online with agents installed. So I do not have first-boot.json file populated in my base image and hence none of the VMs also will have this file.

It is one of the same reason for which I had to use knife exec to make then enroll to a role in chef server. What will be the recommended method here ?

Thanks and Regards,