5

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
me-na-ger-ie
  • 51
  • 1
  • 2

2 Answers2

4

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!

Lodewijk Bogaards
  • 19,777
  • 3
  • 28
  • 52
  • What you've said here makes a lot of sense and I've actually been thinking along similar lines as far as complexity goes so I think I'll do it the way you suggest. Thanks very much! – me-na-ger-ie Oct 14 '13 at 17:08
  • Just an update... Implemented the changes and things are much more manageable. Thanks for the assistance. – me-na-ger-ie Oct 14 '13 at 19:41
  • 1
    Puppet URLs are more for sharing between master/agent nodes: http://docs.puppetlabs.com/guides/file_serving.html However they don't work for templates, as mentioned here: http://docs.puppetlabs.com/learning/templates.html#refererring-to-template-files-in-modules – xiankai Oct 15 '13 at 13:22
  • Thanks xiankai I updated my answer to include your comment for future reference. – Lodewijk Bogaards Oct 16 '13 at 07:43
1

Once in a module, use

template("${module_name}/xxx.erb")

to reference your template files (works on puppet 4.x. Not sure for previous versions).