Explain the Importance of Roles in Chef server

Chef Server Roles

Roles :

• Custom run-list
• We will create role & upload them to chef-server & assign them to nodes.
• If we have 1000 nodes, need to add a cookbook to the run-list of all 1000 nodes. Its very difficult. Instead, create
role & attach that role to 1000 nodes once. Next time onwards add cookbook to that role. Automatically, all
1000 nodes will get that cookbook.
• So role is one time effort.
• Instead of adding cookbooks to each & every node run-list always, just create a role & attach that role to
nodes.
• When we add a cookbook to that role, it will be automatically applied to all nodes assigned with that role

• Terminate nodes & delete node and apache-cookbook from chef-server.
• Be ready with 2 fresh nodes, bootstrap them and automate chef-client.
• Be inside chef-repo

• vi roles/web.rb
name "web"
description "web server role"
run_list "recipe[apache-cookbook::apache-recipe]","recipe[test-cookbook::test-recipe]","recipe[cookbookname]"

• Upload role to chef server (every time you modify the role)(run inside chef-repo)

• knife role from file roles/web.rb

• Attach role to all nodes (one time effort) (run inside chef-repo)

• knife node run_list set <node_name1> "role[web]“
• knife node run_list set <node_name2> "role[web]"

• To upload cookbook (every time you modify) (run inside chef-repo)

• knife cookbook upload apache-cookbook

• Paste public IP of both nodes in web and verify

(verify attributes & include recipe)

Test
• Modify recipe
• Upload cookbook

Leave a Reply

Your email address will not be published. Required fields are marked *