Templates

Chef dynamically configures software and hosts, and a large part of configuring UNIX-based systems and software involves configuration files. Chef provides a straightforward mechanism to generate configuration files that make it easy to combine configuration data with template files to produce the final configuration files on hosts. These templates are stored in the templates directory inside of a cookbook and use the ERB template language, which is a popular and easy-to-use Ruby-based template language.

Why use templates?

Without templates, your mechanism to generate configuration files would probably look something like this:

File.open(local_filename, 'w') do |f| f.write("<VirtualHost *:#{node['app]['port']}") ... f.write("</VirtualHost>") ...

Get Chef: Powerful Infrastructure Automation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.