Information Technology Reference
In-Depth Information
Attributes and Environments
Environments can contain attributes. Let's experiment with this by creating a
.json
file to
represent a
production
environment. This environment will pin production to the older ver-
sion of the
apache
cookbook, the
0.1.0
that is not currently under development. We'll also
make sure that in the production environment, the message of the day is set to a suitable mes-
sage of the day for production. Create the file
chef-playground/environments/production.json
with the code provided in
Example 15-2
.
Example 15-2. chef-playground/environments/production.json
{
"name"
:
"production"
,
"description"
:
"For prods!"
,
"cookbook_versions"
: {
"apache"
:
"= 0.1.0"
},
"json_class"
:
"Chef::Environment"
,
"chef_type"
:
"environment"
,
"override_attributes"
: {
"motd"
: {
"message"
:
"A production-worthy message of the day"
}
}
}
Then run
knife environment from file
passing in the
production.json
file, as follows:
$
knife environment from file production.json
Updated Environment production
knife show environment
displays more detailed information about an environment:
$
knife environment show production
chef_type: environment
cookbook_versions:
apache: = 0.1.0
default_attributes:
description: For prods!
json_class: Chef::Environment
name: production
override_attributes: