Exploring templates
A template is an Embedded Ruby (ERB) file that is used to create configuration files based on variables and logic defined by a cookbook. A template can contain mixed Ruby code or expressions; it provides a great way to manage configuration files on any node.
Templates are used with a template resource, and each resource includes actions, attributes, and file sources. Template resources are very close to file resources; the only difference is that templates are based on Ruby code, and on the other hand, file resources are used to copy files to a particular location.
Templates should have the following two components:
A template resource, which instructs the chef-client to perform any action
A template file in the
templates
folder
The folder structure of cookbook templates will look similar to the following:
default
ubuntu-12.04
ubuntu-14.04
If we notice our cookbooks
directory, we will see that the templates
folder is already created by Knife. Let's complete our recipe and...