Joining multiple template files with Hiera

58 views
Skip to first unread message

Kevin Freels

unread,
Mar 24, 2015, 11:54:03 AM3/24/15
to puppet...@googlegroups.com
Greetings!!

DISCLAIMER: New to Hiera.

I'm trying to so something which seems should be really easy to do. However, all the examples I've seen so far seem to be overly complicated, and I need to get this up without brute-forcing it..

What I want to do build dynamically a file based on multiple templates, essentially concatenating them together. The multiple templates would be based on FQDN/role/common so that a system would pick up the common template *and* any other specified in the separate YAML's, and then munge them altogether into one file.

For example, something like a resolv.conf file could be different for each host but built based on all three of those factors; there would be a base resolv.conf file (common), one for the environment (role), and one final file based on it's sole status (FQDN). All of these are neither exclusionary nor inclusive. In addition, I'd like to be able to have multiple templates available inside the YAML so that a system that might have multiple roles would need multiple templates.

I know you can join templates under the "template" function, but that's not dynamic nor manageable (though I tried with variables); if you need to change the files in the join, you'd have to change the .pp file instead of the YAML, defeating the purpose of Hiera.

I've tried many methods, and have put the file names in a hash, which works just fine:

[root@puppet hierdata]#  hiera hiera_test fqdn=install-test
{"install_erb"=>"nos_details/hiera_test_install-test.text.erb",
 "common_erb"=>"nos_details/hiera_test_common.txt.erb"}

However, the best I could get was all the hash elements strung together, as in:

 common_erbnos_details/hiera_test_common.txt.erbinstall_erbnos_details/hiera_test_install-test.text.erb

This obviously causes puppet to bail.

I thought about naming the hash elements things like "file_common", "file_1", "file_2", etc., and use the merge abilities already present. But that can get unweildy as well. I also tried a few tests with "create_resources", but with similar failing results.

Is there any *simple* way to do this? Even a cheesy hack will work for now.

Thanks for any help/tips/gotchas.

....kevin


Kevin Freels

unread,
Mar 24, 2015, 7:30:52 PM3/24/15
to puppet...@googlegroups.com
In the words of Emily Litella, "Nevermind".

I found puppetlabs-concat, it does exactly what I'm looking for. I knew once I posed the question, the answer would pop out at me.

Thanks!!

....k
Reply all
Reply to author
Forward
0 new messages