4

In the module I'm currently working on, I got a load of configuration options that need to be set, have default values ... and should be fragmented into shorter template files as else it would be a scrolling nightmare.

The recommended way to do so was to use some third party modules. Is there no built in way?

7

Another possible solution that surprisingly works (and about which I couldn't find any documentation), is the array syntax inside the template() function:

file { "${location}/final-file.php":
    ensure  => file,
    content => template(
        'wppuppet/template.a.erb',
        'wppuppet/template.b.erb',
        'wppuppet/template.c.erb'
    ),
}
  • Cool! How did you find it out? – Adam Ryczkowski May 3 '14 at 6:30
  • Assumption > Try > Error > Repeat and a lot of patience in between :) ... My IDE only supports PHP and JS :P – kaiser May 3 '14 at 6:54
  • 1
    This is in the puppetlabs documentation: docs.puppetlabs.com/guides/templating.html#combining-templates – daxlerod May 3 '14 at 15:49
  • @daxlerod then I overread that part :P Wonder why those modules then are so popular. – kaiser May 3 '14 at 16:57
  • 1
    The modules typically offer some more flexibility, you may not know ahead of time where your fragments will come from. Also, take a look at how the mcollective::plugin type in the puppetlabs-mcollective module uses datacat to combine multiple directories. github.com/puppetlabs/puppetlabs-mcollective – daxlerod May 3 '14 at 21:10
5

One possible solution is to fetch templates in variables. Then concatenate the string and push it into an inline_template():

$a = template( 'wppuppet/my-file.a.erb' )
$b = template( 'wppuppet/my-file.b.erb' )
$c = template( 'wppuppet/my-file.c.erb' )

file { "${location}/final-file.php":
    ensure  => file,
    content => inline_template( "${a}${b}${c}" ),
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.