- Chef - Chef-Client Run
- Chef - Nodes
- Testing Cookbook with Test Kitchen
- Chef - ChefSpec
- Chef - Foodcritic
- Chef - Testing Cookbooks
- Chef - Chef-Shell
- Chef - Chef-Client as Daemon
- Chef - Environment
- Chef - Roles
- Chef - Cookbook Dependencies
- Chef - Cookbooks
- Chef - Solo Setup
- Chef - Knife Setup
- Chef - Test Kitchen Setup
- Chef - Client Setup
- Chef - Workstation Setup
- Chef - Version Control System Setup
- Chef - Architecture
- Chef - Overview
- Chef - Home
Advanced Chef
- Chef - Community Cookbooks
- Chef - Files & Packages
- Chef - Blueprints
- Lightweight Resource Provider
- Chef - Resources
- Chef - Cross-Platform Cookbooks
- Chef - Scripts for Data Bags
- Chef - Data Bags
- Chef - Environment Variable
- Chef - Definition
- Chef - Libraries
- Chef - Ruby Gems with Recipes
- Chef - Plain Ruby with Chef DSL
- Chef - Templates
- Dynamically Configuring Recipes
Chef Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Chef - Roles
Roles in Chef are a logical way of grouping nodes. Typical cases are to have roles for web servers, database servers, and so on. One can set custom run pst for all the nodes and override attribute value within roles.
Create a Role
vipin@laptop:~/chef-repo $ subl roles/web_servers.rb name "web_servers" description "This role contains nodes, which act as web servers" run_pst "recipe[ntp]" default_attributes ntp => { ntpdate => { disable => true } }
Once we have the role created, we need to upload to the Chef server.
Upload Role to Chef Server
vipin@laptop:~/chef-repo $ knife role from file web_servers.rb
Now, we need to assign a role to a node called server.
Assign a Role to Node
vipin@laptop:~/chef-repo $ knife node edit server "run_pst": [ "role[web_servers]" ] Saving updated run_pst on node server
Run the Chef-Cpent
user@server:~$ sudo chef-cpent ...TRUNCATED OUTPUT... [2013-07-25T13:28:24+00:00] INFO: Run List is [role[web_servers]] [2013-07-25T13:28:24+00:00] INFO: Run List expands to [ntp] ...TRUNCATED OUTPUT...
How It Works
Define a role in a Ruby file inside the roles folder of Chef repository.
A role consists of a name and a description attribute.
A role consists of role-specific run pst and role-specific attribute settings.
Every node that has a role in its run pst will have the role’s run pst exacted into its own.
All the recipes in the role’s run pst will be executed on the node.
The role will be uploaded to Chef server using the knife role from file command.
The role will be added to the node run pst.
Running Chef cpent on a node having the role in its run pst will execute all the recipes psted in the role.