passing array element to hiera lookup as a key

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

alechiko gravatar image

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

I am using Puppet 3.8.4 and Hiera 3.0.1 on Centos 6.6

My hiera currently looks like this:

testmodule::install::certificates:
  test1.domain.com:
    certificatefile: 'certificate1.crt'
    certificatepass: 'testpass1'
  test2.domain.com:
    certificatefile: 'certificate2.crt'
    certificatepass: 'testpass2'
  test3.domain.com:
    certificatefile: 'certificate3.crt'
    certificatepass: 'testpass3'

The init.pp in my module looks like this:

class testmodule (
  $certificates = hiera('test module::install::certificates'), 
 )
{
    $domains = [
      'test1.domain.com',
      'test2.domain.com',
      'test3.domain.com',
    [

  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: test2.domain.com['certificatefile']
Notice: /Stage[main]/Testmodule/Testmodule::Install[test2.domain.com]/Notify[This is the certificate file: test2.domain.com['certificatefile']]/message: defined 'message' as 'This is the certificate file: test2.domain.com['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

Comments

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 -0600 )edit