Search code examples
puppethiera

How to access a value in an hiera hash directly with puppet lookup?


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.


Solution

  • 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