Templates
As we mentioned earlier, templates are Embedded Ruby (ERB) templates, which can be used to generate configuration files based upon some variables and logic. These files may contain Ruby statements and expressions. To make use of templates, one has to use the template resource in a cookbook and specify in the source the path to the template itself. The template file is placed in the templates
directory of a cookbook.
Unless you are creating your cookbooks manually, Knife will automatically take care of creating the templates
directory structure. A template is stored in the cookbook_name/templates
directory and is referenced by the template resource in the cookbook recipe. Generally, cookbooks are developed, keeping different platforms in mind, and hence one can keep different files per platform type using the concept of file specificity. The template
directory can have the following structure on Chef repo:
templates |-- host-node[:fqdn] |-- node[:platform]-node[:platform_version...