Search code examples
puppet

Require defined type in hash table


I have a defined type called profile_winsql_dbengine::resources::sqlconfighelper which calls an exec block and works fine.

I am using the following create resource statement in my init manifest:

create_resources( profile_winsql_dbengine::resources::sqlconfighelper, $sqlconfighelperhash )

The hash is declared as follows:

$sqlconfighelperhash = {
    'config1' => {
      param1     => $param1,
      param2     => $param2,
    },
    'config2' => {
      param1     => $param1,
      param2     => $param2,
      require    => Profile_winsql_dbengine::Resources::Sqlconfighelper['config1'],
    }
}

Everything works as expected, with the exception of the require. The require throws a compilation error, telling me that it can't find Profile_winsql_dbengine::Resources::Sqlconfighelper['config1']

The syntax compiles, and without the require it applies the profile as expected. What should I do differently, to make the require work?


Solution

  • I can't reproduce this using latest Puppet 5.3.4.

    My code:

    # /tmp/test.pp
    define test::my_type($message, $withpath) {
      notify { $name:
        message  => $message,
        withpath => $withpath,
      }
    }
    
    class test (
    ) {
      $data = {
        'message1' => {
          message  => 'I am message 1',
          withpath => false,
          require  => Test::My_type['message2'],
        },
        'message2' => {
          message  => 'I am message 2',
          withpath => false,
        }
      }
      create_resources(test::my_type, $data)
    }
    
    include test
    

    Then:

    $ puppet apply /tmp/test.pp
    Notice: Compiled catalog for alexs-macbook-pro.local in environment production in 0.06 seconds
    Notice: I am message 2
    Notice: /Stage[main]/Test/Test::My_type[message2]/Notify[message2]/message: defined 'message' as 'I am message 2'
    Notice: I am message 1
    Notice: /Stage[main]/Test/Test::My_type[message1]/Notify[message1]/message: defined 'message' as 'I am message 1'
    Notice: Applied catalog in 0.05 seconds
    

    Probably you have a typo somewhere maybe?