Search code examples
yamlpuppethierarchyhiera

Interpretting nested yaml with hiera?


I saw a lot of questions close to this but not exactly with what I am asking, so please help me out on this. In my yaml file I have a hierarchy such as

## application.yaml
application::params::api:
  consumers:
    app1:
      id:  'appname1'
      key: 'key1'
    app2:
      id:  'appname2'
      key: 'key2'

Then in the applications params

## params.pp
class application::params {
    $application = hiera('application::params::api->????->app1->???->id')
}

The question marks are whatever I am using to run onto the next level of hierarchy, I'm uncertain as what my separators should be? I see this sprinkled throughout our code, but cannot find an example of how it is loaded / called into hiera

Would I just use $application = hiera('application::params::api::app1::id') ?


Solution

  • The :: notation is Puppet specific and have no special meaning to Hiera but it is possible to navigate into details using dotted keys. The expression hiera('application::params::api.consumers.app1.id') will return the value 'appname1' when using the data from your example.

    More information about Hiera Lookup Keys.