Reputation: 335
Let's say there is an hiera hash:
foo::bar:
key1: 'value1'
key2: 'value2'
Is there any possibility to lookup the value of key1
directly with the lookup function?
I thought of something like:
class myclass (
String $value1 = lookup('foo::bar::key1'),
) {
...
}
The only way I could solve this, is to lookup the Hash and acces the value later with hash['key1']
, but maybe there is a more clean way to do this.
Upvotes: 0
Views: 2936
Reputation: 4027
This is now possible in puppet (v6 and later)! You use dot notation
lookup('foo::bar.key1')
See the puppet documentation here: https://puppet.com/docs/puppet/7/hiera_automatic.html#access_hash_array-elements_keysubkey_notation
Upvotes: 1
Reputation: 3671
Unfortunately, there isn't a way to do this in Puppet using just lookup
.
Fundamentally, lookup
works by looking up Hiera keys, which are unrelated to hash keys. A Hiera key of the form foo::bar::baz
is effectively a single unstructured string - it doesn't imply that there are hashes called foo
or foo::bar
. The ::
is just part of the key string - it isn't syntactic sugar for a hash lookup, as is, for example, .
in JavaScript.
lookup
is documented at
https://puppet.com/docs/puppet/latest/hiera_automatic.html
Upvotes: 2