Ask Your Question

Merging multiple files with Hiera

asked 2014-07-01 09:29:57 -0600

mapa3m gravatar image

updated 2014-07-02 06:44:04 -0600

I have a puppet module that defines customer access. The way it's currently done is with a puppet class, where all the customers are defined (very bad, trying to get away from it). Example:

customer::access{'customer1':param1=>'a', param2=>'b'}
customer::access{'customer2':param1=>'c', param2=>'d'}

And so on, few hundred of these, and growing. As part of the new customer provisioning process, other teams would have access to this data, so it needs to be moved out of Puppet entirely. I would like to move it into Hiera, checked into version control separately from the main code base. What I would also like is to have one file per customer, rather than having them all defined in a single file. So the directory structure would look something like this:


{' 'customer1': { 'param1' : 'a', 'param2:'b' } }


{' 'customer2': { 'param1' : 'c', 'param2:'d' } }

All the customers are provisioned on a group of servers (all customers on all servers), so this would essentially be a single hierarchical point.

Is there a way to do this with Hiera? Somehow tell it to load an entire directory, rather than a single file?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2014-07-03 09:17:19 -0600

gh gravatar image

Your customer class could take a hash of titles and parameter values to pass to customer::access with createresources(). This would allow you to put the data in Hiera. To merge the results from all levels in Hiera, you can use hierahash(). Check out my types modules for an example.

edit flag offensive delete link more


Hi GH, I agree that it is possible that the the class could use a hiera hash of titles/parameters and then create the resources using createresources() but I don't understand how that hash can be derived from several files in the same hiera folder. OP does not want to "merge the results from all levels in hiera", he wants to merge all files from one level in hiera. So I don't think you're solution would work. . I think what he needs is something like a 'calling_class' fact that would pick the correct hiera file, but in his case, he needs a 'calling_title' or 'calling_namevar' fact which I don't think exists..?

Gary S gravatar imageGary S ( 2014-07-03 09:49:07 -0600 )edit

answered 2014-07-08 09:08:52 -0600

mapa3m gravatar image

updated 2014-07-08 09:11:29 -0600

I ended up writing a custom backend to load multiple JSON files. It's a little bit crude at this point, but seems to do the job.

edit flag offensive delete link more

answered 2014-07-02 18:10:15 -0600

Gary S gravatar image

I don't think its possible to load a whole directory, or use wildcards. See question 1149. Let me know if you do find a way to do it!

If you don't mind having all customer defs in a single file then you can easily do it by creating the file then explicitly naming it in your hiera hierarchy.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-07-01 09:29:57 -0600

Seen: 1,140 times

Last updated: Jul 08 '14