Using multiple sources for Puppet templates

Stephan Koene
19-12-2013

I this version I would like to talk about using multiple sources for templates and the function that isn’t often used.

We all know that we can use multiple sources for files:

File {‘⁄etc⁄myfile’:
ensure => present,
source => [“puppet:///modules/${module_name}/${some_var}/possiblesource”,
“puppet:///modules/${module_name}/existsforsure/fallback”]
}

… and multiple sources for templates:

File {‘⁄etc⁄myotherapp.conf’:
ensure => present,
content => template([“modules/${module_name}/first_half.erb”,
“modules/${module_name}/second_half.erb”]
}

But the problem is that Puppet will concatenate these sources. Although this might be useful / wanted in some cases, we came across a situation where this wasn’t ideal.

Looking for a solution, we found the function (‘multi_source_template’) written by R.I. Pienaar (devco.net) which allows the the use of multiple sources for templates in the same way as these are handled by the file resource:

File {‘⁄etc⁄myapp.conf’:
ensure => present,
content => multi_source_template (
“${module_name}/${appname}/config.erb”,
“${module_name}/common/config.erb”
)
}

Credits: R.I Pienaar (devco.net), R. Van Leeuwen (reinoud.van.leeuwen.net).

LEAVE A REPLY

1 Comment

you might also like