Hiera lookup in hiera lookup

42 views
Skip to first unread message

Erwin Bogaard

unread,
May 18, 2021, 4:23:18 AM5/18/21
to Puppet Users
Hi,

I've been looking for this for a ling time, but can't find a definitive answer to my question: is it possible to use a lookup in a lookup?

For example:
aaa::bbb: "mvn:com.xxx.bus/xxx-features/%{lookup('xxx::apps::env_hash.%{lookup('xxx::apps::env')}.yyy.version')}/xml/features"

Should lead to the following string:
"mvn:com.xxx.bus/xxx-features/2.0.4/xml/features"

If "xxx::apps::env" has the value 'test'.
And "xxx::apps::env_hash.test.yyy.version" has the value '2.0.4'.

The idea is that I would like one variable, "xxx::apps::env", make it possible to switch in a hash from the 'test'-branch to the 'prod'-branch, for example. Where each branch in that hash contains certain specified different versions and/or other variables.

Thanks!

Martin Alfke

unread,
May 18, 2021, 4:38:53 AM5/18/21
to puppet...@googlegroups.com
Hi Erwin,

Nested lookups are possible.

We did a blog post on this topic:

Just be sure:

A nested lookup (like in your example) always returns a string.
If you need arrays or hashes within a nested lookup you must use the alias function.

hth,
Martin

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/5068271c-bac1-4beb-b097-91803dbf3e2en%40googlegroups.com.

Benjamin Ridley

unread,
May 18, 2021, 5:17:00 AM5/18/21
to puppet...@googlegroups.com
Hi Erwin and Martin,

I think there's a difference here - Erwin it seems you're trying to do nested interpolation, while Martin it appears your example is for lookups nested in hiera data.

Erwin as far as I'm aware, nested interpolation in the manner you suggest is not possible. At least I've not been able to get it to work, and I found this engineering ticket a while back: https://tickets.puppetlabs.com/plugins/servlet/mobile#issue/HI-532

You can sometimes usually work around this by restructuring your hiera data. In your example, perhaps you could have a prod.yaml and a test.yaml file that each define their own env_hash, and then edit your hiera.yaml so the node includes the correct file based on its environment (if you have environment available as a fact) 



Erwin Bogaard

unread,
May 18, 2021, 4:11:23 PM5/18/21
to Puppet Users
Indeed it was about looking up a value to use as part of a following lookup, so a lookup in a lookup.
I was already afraid this would not be possible.
Thanks for the suggestion of using separate yaml files, I'll explore that idea further.
Reply all
Reply to author
Forward
0 new messages