Information Technology Reference
In-Depth Information
Simulate a Production Environment
Create a directory called
chef-zero
. This will be structured similar to
chef-repo
in
Chapter 9
and
chef-playground
, with
cookbooks
,
environments
, and
roles
as subdirectories. Once you
create the directory, make it the current working directory as follows:
$
mkdir chef-zero
$
cd chef-zero
Create a
chef-zero/environments
subdirectory to contain our environment definitions in the
JSON file format, and make it the current working directory:
$
mkdir environments
$
cd environments
Let's say our
apache
cookbook is ready to go and we are making use of attributes, environ-
ments, and roles in our production environment. First, let's simulate the production environ-
ment with Test Kitchen.
Create an environment definition in
chef-zero/environments
as shown in
Example 15-3
.
This
will represent a
production
environment, like we covered earlier in this chapter. There is
also an attribute set for
node['motd']['message']
as an attribute with override precedence.
Example 15-3. chefdk/chef-zero/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"
}
}
}
Our production environment uses roles. Create a directory parallel to
environments
called
roles
, and make it the current working directory, as follows: