Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble locating templates in Puppet

Tags:

puppet

I can't get my Puppet manifest to find templates the way I'd expect so I thought someone might have a quick answer. I'm new to puppet so just trying to understand all the locations for everything and how to reference files properly. If I'm missing something painfully obvious I apologize.

This works:

file {
     $zabbix_agent_conf:
     owner => root,
     group => root,
     mode => 0644,
     content => template("/etc/puppet/templates/zabbix/files/zabbix_agent_conf.erb"),
     require => Package["zabbix-agent"];
}

This does not:

file {
     $zabbix_agent_conf:
     owner => root,
     group => root,
     mode => 0644,
     content => template("puppet:///templates/zabbix/zabbix_agent_conf.erb"),
     require => Package["zabbix-agent"];
}

My /etc/puppet/puppet.conf:

[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
templatedir=/etc/puppet/templates
prerun_command=/etc/puppet/etckeeper-commit-pre
postrun_command=/etc/puppet/etckeeper-commit-post

[master]
# These are needed when the puppetmaster is run by passenger
# and can safely be removed if webrick is used.
ssl_client_header = SSL_CLIENT_S_DN
ssl_client_verify_header = SSL_CLIENT_VERIFY
like image 816
me-na-ger-ie Avatar asked Oct 14 '13 15:10

me-na-ger-ie


People also ask

How do you use puppet templates?

With a template file: template and eppYou 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.

How are templates developed in puppet?

Templates 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.

What is puppet EPP?

EPP is to the Puppet Programming Language what ERB is to Ruby, and EPP supports the same template tags as ERB.

Which of the following functions will load the contents of an EPP template?

Puppet can evaluate EPP templates with the epp and inline_epp functions.


1 Answers

You cannot use the puppet URI scheme in combination with the template function as of yet. According to the docs:

Note that the path to the template doesn’t use the same semantics as the path in a puppet:/// URL. Sorry about the inconsistency. (Source)

Furthermore:

(If a file cannot be located within any module, the template function will fall back to searching relative to the paths in Puppet’s templatedir. However, using this setting is no longer recommended.) (Source)

This means that in order to use the templatedir the template function expects a simple relative path:

template("zabbix/zabbix_agent_conf.erb")

It is not recommended to use the templatedir. There is a good reason for this. It is better to group files together under the common denominator of a module, otherwise things can get pretty messy pretty fast. Think of modules as a good way to group all puppet resources that belong to each other: manifests, files, templates, extensions and tests.

So I would recommend creating a zabbix module. Place your puppet code in a zabbix class within a init.pp in the manifest directory of your zabbix module. Then you can place your template in the templates directory of your zabbix module and you can reference it by:

template("zabbix/zabbix_agent_conf.erb")

Hope this helps. Good luck!

like image 143
Lodewijk Bogaards Avatar answered Sep 21 '22 17:09

Lodewijk Bogaards