0

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?

Engineer2021
  • 591
  • 7
  • 25
  • Copy and pasting the exact error message might be useful. The first line of the `profiles::logstash::config` class would also be useful to see. Why are you doing an explicity hiera() lookup anyway? Why not just let the [auto-paramater-lookup](http://docs.puppetlabs.com/hiera/1/puppet.html#automatic-parameter-lookup) function? – Zoredache May 29 '14 at 19:47
  • @Zoredache: Because the auto lookup wasn't populating my define. The error message is also in my post. – Engineer2021 May 29 '14 at 19:53
  • You are mistaken. The concatenation happens when you use the variable in a string context. Puppet coerces hash into a string representation. That is what you are observing. – Felix Frank May 30 '14 at 12:41

1 Answers1

1

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.

Felix Frank
  • 3,063
  • 1
  • 15
  • 22