Puppet TemplateTemplates are written in a special language that generates text from data. Templates are documents that gather code, data, and literal text to generate the final output. The main purpose of the template is to handle a complex part of the text with easy inputs. We are using templates in Puppet to handle the content of configuration files. Languages of TemplatePuppet supports two Templating languages:
Evaluating TemplatesTo evaluate the template, use the following function: We can define a template's full path, or drag all templates in Puppet's templatedir. The most commonly used location of puppetdir is /var/puppet/templates. We can find the location of a directory by running the Puppet --configprint templatedir. Clients are not evaluating templates; the parser evaluates it. Hence, if you use puppetmasterd, you only need to have the template on the server, and you never need to download it to the client. The client treats the same to both, using a template and defining all the content of a file as a string. This indicates that the client-specific variables are first discovered in the puppet startup phase by puppetmasterd. Using TemplatesLet's see an example to generate the tomcat configuration for testing sites: Following is the template definition: This will push each template file into a separate file and then we need to tell Apache to load these configurations file: Combining TemplatesTo combine two templates use the following command: Iteration in TemplatesTemplates also supports array iteration in Puppet. We have template like the following: We will get the following output: Condition in TemplatesTemplates also support conditions. We can easily write conditional content in a file:
Next TopicPuppet Custom Function
|