How to apply configuration on multiple nodes with same environment


#1

I’m trying to apply a recipe on different nodes whose environment is ‘production’. If there are 100 nodes whose environment say ‘production’, then I need to apply all configuration on all the nodes.
Help me how can I do it.


#2

if you are running one common recipe on all of your nodes, then something like this should work…

if node.chef_environment == 'production'
  include your_production_recipe
end

#3

Hi @waseemahammed

I will answer your question in two parts:

  1. Assign particular role to all the nodes present in production environment: Use of knife exec might be helpful. This is how you can use it:

     Write following ruby code and save it to .chef/scripts/production_env.rb:
     nodes.transform("chef_environment:production"){|n| puts n.run_list.add("role[role1]"); n.save }
     
    Execute following command from chef repo:
    knife exec production_env.rb
    

This will add role1 to all the nodes which are present in test environment.

2 Run chef Client in all the production environment nodes: I am also struggling to find this solution. Possible choices are as follows:

    a. Schedule chef-client run in all the servers.
    b. Use chef push jobs
    c. If the servers are Linux machines: use knife ssh
    d. If the servers are windows machines: use knife winrm

Hope this will help.


#4

Thanks @kawolfe :slight_smile:


#5

Thank you @manishmehra :slight_smile: