Information Technology Reference
In-Depth Information
Attributes and Roles
Roles can contain attributes as well.
Create a
.json
file to represent a
base
role. This role will include references to the
chef-
client::delete_validation
and
chef-client::default
recipes, both of which we re-
commended running on every node in
Chapter 10
. In this case, we'll also set an attribute to
tell the
chef-client::default
recipe to set the
init_style
to use
runit
instead of the de-
fault. Create the file
chef-playground/roles/base.json
with the code provided in
Example 14-2. chef-playground/roles/base.json
{
"name"
:
"base"
,
"description"
:
"Common recipes for all nodes"
,
"json_class"
:
"Chef::Role"
,
"chef_type"
:
"role"
,
"run_list"
:
[
"recipe[chef-client::delete_validation]"
,
"recipe[chef-client]"
]
,
"default_attributes"
: {
"chef_client"
: {
"init_style"
:
"runit"
}
}
}
Then run
knife role from file
passing in the
webserver.json
file. Similar to data bags,
knife role from file
assumes
webserver.json
is located in a subdirectory named
roles
,
and not in the current directory:
$
knife role from file base.json
Updated Role base!
When you run
knife role show base
as follows, notice that the role has attributes set as
well as items in a run list:
$
knife role show base
chef_type: role
default_attributes: