1

I'd like to use template() to concatenate some files. I read this question, which is fine if you know exactly how many files you want to concat. What if I just have an array of input file names?

$files = ['mymod/a.erb', 'mymod/b.erb', 'mymod/c.erb'] file { "/var/foo/final": content => template ($files) # <-- error, can't convert Array to String } 

I'd like to avoid having to write a parser function.

1 Answer 1

3

This is not possible at the moment. There was a Puppet issue submitted for it and a fix proposed but does not seem like there's any rush to implement it.

As a possible workaround, you could have one template include others:

<% @template_array.each do |val| -%> <% scope.function_template(val) %> <% end -%> 

Forewarning, I have not tested this but I believe it should work.

4
  • I will try it out and report back. I was going to ask if it's possible to "call" the puppet template() function from inside Proper Ruby. If so, you could actually skip the extra file and go straight for inline_template('@arr.reduce ("") { |str, f| str + scope.function_template(f) }') Commented Mar 30, 2015 at 9:32
  • Oh, good idea. I tend to go with separating logic and presentation so I avoid inline_template but this is a use case that may be appropriate. Commented Mar 30, 2015 at 12:17
  • If your manifest does this a lot (e.g. in a defined type that is instantiated in large numbers), this will cause a measurable performance hit. Apart from some boiler plate, a custom function will really not be that much more code, but saves CPU. Commented Mar 30, 2015 at 12:24
  • Thanks for the advice, @FelixFrank, I will keep it in mind. It's for a monitoring module, so I can keep "things to monitor" in partial config files and assign those on a per-host basis. The module should be instantiated once per host, so I think a performance hit should be acceptable. Commented Mar 30, 2015 at 12:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.