Information Technology Reference
In-Depth Information
Because we will be using attributes in this version of the
apache
cookbook, create a
de-
fault.rb
attributes file.
Chef Development Kit:
$
chef generate attribute default
Chef Client:
$
touch attributes/default.rb
Provide default settings for all the attributes we're going to be using in our cookbook by cre-
ating
attributes/default.rb
as shown in
Example 15-7
.
In order to test attribute precedence,
we're going to set the default values for
node['apache']['port']
and
node['motd']['message']
to something different than what is being set in the role and in
the environment we are using. We also moved the root location for our
index.html
file to an
attribute.
Example 15-7. chefdk/chef-zero/apache/attributes/default.rb
default
[
'apache'
][
'document_root'
] =
'/var/www/html'
default
[
'apache'
][
'port'
] =
3333
default
[
'motd'
][
'message'
] =
'Default message'
Create the recipe file
recipes/default.rb
as shown in
Example 15-8
.
Most of this recipe code
should look familiar.
We are adding a new
template
resource to create a
custom.conf
file on the sandbox node,
along with an accompanying
directory
resource to create the required directory on the
node.
custom.conf
is an optional file used to configure
apache
web server settings. In this
file we're going to set the default listening port and the document root.
We are introducing an alternative
template
resource syntax:
template '/etc/httpd/conf.d/custom.conf' do
...
variables(
:document_root => node['apache']['document_root'],
:port => node['apache']['port']
)