Ask Your Question
1

How to reference Hiera array/hash inside Hiera?

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

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
---
dev_hosts:
- 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

Comments

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 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

mmedvede gravatar image

I think this answers it: https://tickets.puppetlabs.com/browse...

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

2 followers

Stats

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

Seen: 346 times

Last updated: Dec 02 '14