Information Technology Reference
In-Depth Information
...
end
You can pass a hash of variables to be used when the template file is evaluated using the
variables()
attribute. This is a way to pass local instance variables in a recipe to a tem-
plate, or to use shorter, more memorable variable names in the template file.
Example 15-8. chefdk/chef-zero/apache/recipes/default.rb
#
# Cookbook Name:: apache
# Recipe:: default
#
# Copyright (C) 2014
#
#
#
package
'httpd'
service
'httpd'
ddo
action
[
:enable
,
:start
]
end
end
# Add a template for Apache virtual host configuration
template
'/etc/httpd/conf.d/custom.conf'
ddo
source
'custom.erb'
mode
'0644'
variables
(
:document_root
=>
node
[
'apache'
][
'document_root'
]
,
:port
=>
node
[
'apache'
][
'port'
]
)
notifies
:restart
,
'service[httpd]'
end
end
document_root
=
node
[
'apache'
][
'document_root'
]
# Add a directory resource to create the document_root
directory document_root
ddo
mode
'0755'
recursive
true
end
end