passing array element to hiera lookup as a key

asked 2018-01-24 11:41:37 -0500

alechiko gravatar image

updated 2018-01-25 01:43:11 -0500

I am using Puppet 3.8.4 and Hiera 3.0.1 on Centos 6.6

My hiera currently looks like this:

    certificatefile: 'certificate1.crt'
    certificatepass: 'testpass1'
    certificatefile: 'certificate2.crt'
    certificatepass: 'testpass2'
    certificatefile: 'certificate3.crt'
    certificatepass: 'testpass3'

The init.pp in my module looks like this:

class testmodule (
  $certificates = hiera('test module::install::certificates'), 
    $domains = [

  testmodule::install { $domains:
    certificates => $certificates,

The install.pp in my module looks like this:

define testmodule::install ($certificates)

       $domain = $name
       $certificatefqdn = $certificates["$domain"]
       $certificatefile = $certificatefqdn['certificatefile']
       $certificatepass = $certificatefqdn['certificatepass']
       notify{"This is the certificate file: $certificatefile" :}

I'm expecting to see an output like this for each of the elements in the domain array:

Notice: This is the certificate file: certificate2.crt
Notice: /Stage[main]/Testmodule/Testmodule::Install[certificate2.crt]/Notify[This is the certificate file: certificate2.crt]/message: defined 'message' as 'This is the certificate file: certificate2.crt'

Instead I see this:

Notice: This is the certificate file:['certificatefile']
Notice: /Stage[main]/Testmodule/Testmodule::Install[]/Notify[This is the certificate file:['certificatefile']]/message: defined 'message' as 'This is the certificate file:['certificatefile']'

How can I correctly access the keys in the nested hash in hiera using the elements in domains as the initial key?

edit retag flag offensive close merge delete


hiera returns a string not a hash - you want hiera_hash. You are also on a version that has EOL - upgrade and use hiera 5 and lookup() instead

Henrik Lindberg gravatar imageHenrik Lindberg ( 2018-02-04 04:16:04 -0500 )edit