Hiera concatenated lookup from yaml

hierapuppet

I am trying to configure the puppet-logstash module via Hiera. When I make the call to hiera('profiles::logstash::config'), the return value is a concatenated string. It tells me that it cannot convert a String into a hash.

shipper.pp

class profiles::logstash::shipper() {

  $shipper_config = hiera('profiles::logstash::config')

  notice("${shipper_config}")
  class { 'logstash':
    ensure  => 'present',
    version => '1.4.1-1_bd507eb',
    status  => 'enabled',
  }

  profiles::logstash::config { $shipper_config: }

  include logstash
}

hostname.yaml

classes:
  - os::repo
  - profiles::logstash::shipper

profiles::logstash::config:
  - {content: this is a test, order: 10}

Output when used with notice():

order10contentthis is a test

Did I order my YAML wrong?

Best Answer

You can replace the hash_extract logic by a simple

$logstash_configs = hiera('profiles::logstash::config_settings')
create_resource('profiles::logstash::config',$logstash_configs)

(minus the notify resources, those will need to move into the defined type profiles::logstash::config.)

To make this work, the value must use the desired resource title as a key in the nested hash:

profiles::logstash::config_settings:
  shipper:
    content: 'this is a test'
    order: '10'

The config_array is obsolete then.

Note that hiera_hash is only needed if you wish to merge hash values from several hierarchy levels. Hash values should normally be retrieved using plain hiera calls.