Ask Your Question

Default ::params style values for defines

asked 2015-07-14 08:42:42 -0500

simh gravatar image


I am wondering how to achieve something like

    define my_something (
    $param1 = $::my_something::params::parameter1,
    $param2 = $::my_something::params::parameter2,
         notify {"notify1 : param1 is: $param1 ":}
         notify {"notify2 : param1 from params is: $::my_something::params::parameter1":}

    class my_something::params {
        parameter1 = 'value1'
        parameter2 = 'value2'

And I am trying to override this in hiera with something like:

my_something::param1: "super_value1"

And when I override this then it works perfect but the default value, from params, is not being used. And if I add:

include ::my_someting::params

in the define then notify2 works but the notify1 one still does not.

I checked, for example, puppetlabs-apache and in vhost define is used params default value (and I expect this works, could not test this) - so where am I doing something wrong? Any ideas?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-14 10:45:30 -0500

cosman2001 gravatar image

In order to have the mysomething::params in your define statement they would need to be evaluated before the define. Normally this is easily done by using the inherit mysomething::params keyword.

define my_something (
    $param1 = $::my_something::params::parameter1,
    $param2 = $::my_something::params::parameter2,
 ) inherit my_something::params {

Since defines do not have data binding they do not have automatic hiera key lookup for their parameters. So another option is to use the hiera function like below.

define my_something (
    $param1 = hiera('my_something::key1'),
    $param2 = hiera('my_something::key2'),


The only issue here is that defines usually require unique name parameters which can only be passed in. But there are many times when you need to lookup information in hiera. If your looking up information in hiera, also be aware that each lookup causes a delay in catalog compilation. So if your doing this 1000 times it would be better to just hard code the value somewhere else (possibly an outer class or default value).


class make_some_defines(

# this is my make believe for loop
  (1..1000).each |String $name| {
       param1 => $class_param1,
       param2  => $class_param2

edit flag offensive delete link more


Hi, thanks for the reply. This is what I found in the internet... but the again the same thing , that I am trying to use, is used in puppetlabs-apache, for example in vhost. Do you know how and why that works there?

simh gravatar imagesimh ( 2015-07-15 01:15:41 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-07-14 08:42:42 -0500

Seen: 154 times

Last updated: Jul 14 '15