Puppet Templates
• Templates are documents that combine code, data, and literal text to produce a final rendered output
• The goal of a template is to manage a complicated piece of text with simple inputs
• In Puppet, you’ll usually use templates to manage the content of configuration files
Templating Language
• Templates are written in a templating language, which is specialized for generating text from data
• Puppet supports two templating languages:
• Embedded Puppet (EPP) uses Puppet expressions in special tags
• It’s easy for any Puppet user to read, but only works with newer Puppet versions
• Embedded Ruby (ERB) uses Ruby code in tags
• You need to know a small bit of Ruby to read it, but it works with all Puppet versions
With Template
• You can put template files in the templates directory of a module
• EPP files should have the .epp extension, and ERB files should have the .erb extension
# epp(<FILE REFERENCE>, [<PARAMETER HASH>])
file { '/etc/ntp.conf': ensure => file, content => epp('ntp/ntp.conf.epp', {'service_name' => 'xntpd', 'iburst_enable' => true}), # Loads
/etc/puppetlabs/code/environments/production/modules/ntp/templates/ntp.conf.epp } # template(<FILE REFERENCE>, [<ADDITIONAL FILES>, ...])
file { '/etc/ntp.conf': ensure => file, content => template('ntp/ntp.conf.erb'), # Loads /etc/puppetlabs/code/environments/production/modules/ntp/templates/ntp.conf.erb }
Comments
Post a Comment