Templates are written in a specialized templating language that generates text from data. Use templates to
manage the content of your Puppet configuration files via the content
attribute of the file
resource type.
Templating languages
- Embedded Puppet (EPP) uses Puppet expressions in special tags. EPP works with Puppet 4.0 and later, and with Puppet 3.5 through 3.8 with future parser enabled.
-
Embedded Ruby (ERB) uses Ruby code in tags, and requires some Ruby knowledge. ERB works with all Puppet versions.
When to use a template
Templates are more powerful than normal strings, and less powerful than modeling individual settings as resources. Whether to use a template is mainly a question of the complexity of the work you're performing.
When you're managing simple config files, a template generally isn't necessary because strings in the Puppet language allow you to interpolate variables and expressions into text. For short and simple config files, you can
often use a heredoc and interpolate a few variables, or do something like ${ $my_array.join(', ') }
.
Use a template if you’re doing complex transformations (especially iterating over collections) or working with very large config files.
Some situations, however, are too complex for a template to be effective. For example, using several modules that each
need to manage parts of the same config file is impractical with either templates or interpolated strings. For shared configuration
like this, model each setting in the file as an individual resource, with either a custom resource type or an Augeas, concat, or file_line
resource. This approach is similar to how core resource types like
ssh_authorized_key
and mount
work.
- Creating templates using Embedded
Puppet
Embedded Puppet (EPP) is a templating language based on the Puppet language. You can use EPP in Puppet 4 and higher, and with Puppet 3.5 through 3.8 with the future parser enabled. Puppet evaluates EPP templates with theepp
andinline_epp
functions. - Creating templates using Embedded
Ruby
Embedded Ruby (ERB) is a templating language based on Ruby. Puppet evaluates ERB templates with thetemplate
andinline_template
functions.