Ask Your Question

How to reference Hiera array/hash inside Hiera?

asked 2014-12-02 15:50:55 -0500

Tomasz Kuzemko gravatar image

Let's say I have a parameters.yaml document which holds some parameters that I want to reference elsewhere:

# parameters.yaml
- hostA
- hostB

And some other document which declares class parameters in which I want to reference dev_hosts array:

classFoo::hosts: ? # how to reference dev_hosts?
classBar::hosts: ? # how to reference dev_hosts?

Now, I don't want to repeat dev_hosts twice, how can I reference it for classFoo::hosts and classBar::hosts? I know I can lookup plain strings by using interpolation with lookup "%{hiera('::dev_hosts')", but that does not work for arrays/hashes.

I tried YAML anchor/reference mechanism but it works only within a single document.

Is there any way to avoid repetition besides falling back to using site.pp?

edit retag flag offensive close merge delete


I have been struggling with this very thing using the Apache module. I need to be able to reuse a common ALLOW statement in *every* VHOST entry for every server that I build. So have I have had no luck with putting the information in global.yaml and referencing it from <certname>.yaml.

bschonecker gravatar imagebschonecker ( 2016-06-21 08:10:54 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-05 15:15:38 -0500

mmedvede gravatar image

I think this answers it:

So basically you need to do something like:

classFoo::hosts: "%{alias('::dev_hosts')"
classBar::hosts: "%{alias('::dev_hosts')"
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



Asked: 2014-12-02 15:50:55 -0500

Seen: 182 times

Last updated: Dec 02 '14