Book Image

Mastering Chef

By : Mayank Joshi
Book Image

Mastering Chef

By: Mayank Joshi

Overview of this book

Table of Contents (20 chapters)
Mastering Chef
About the Author
About the Reviewers
Knife and Its Associated Plugins
Data Bags and Templates

Managing roles

There are multiple ways to manage roles in the Chef ecosystem.

Using Knife

Knife can be used to create, edit, delete, edit, or show a particular role; alternatively, it can be used to push a role file created using Ruby DSL to the Chef server. Knife can also be used to get a list of all roles defined on the Chef server.

Creating a new role

The knife role create ROLE command can be used to create a new role. Let's use it to create a role called webserver and see the command in action:

$ knife role create webserver

As soon as you issue this command, an editor will open up. The choice of which editor to make use of can be specified by editing the value of the knife[:editor] attribute in your knife.rb file.

The file will look like the following:

   "name": "webserver",
   "description": "",
   "json_class": "Chef::Role",
   "default_attributes": {
   "override_attributes": {
   "chef_type": "role",
   "run_list": [
   "env_run_list": [

This is a simple JSON...