FAQ
How can I use a variable for setting a default parameter in a defined type?
The example below illustrates my problem, the $config parameter ends
up being "undef" while I was expecting it to have the "asdf" value. Any
comments or suggestions would be appreciated


/etc/puppet/modules/sensor/manifests/listner.pp
$myvar="asdf"
define sensor::listner ( $config = $myvar ) {
notify { $config : }
}


/etc/puppet/manifests/site.pp
node 'dev' {
sensor::listner {"test_sensor":}
}


root@dev:/home/ole# puppet agent --test
Info: Retrieving plugin
Info: Caching catalog for dev
Info: Applying configuration version '1366464824'
Notice: undef
Notice:
/Stage[main]//Node[dev]/Sensor::Listner[test_sensor]/Notify[undef]/message:
defined 'message' as 'undef'
Notice: Finished catalog run in 0.02 seconds


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Matthias Saou at Apr 21, 2013 at 6:37 am
    Hi,

    You shouldn't be trying with a variable. Here's what you should
    probably be doing instead :

    /etc/puppet/modules/sensor/manifests/listner.pp
    define sensor::listner ( $config = 'this is the generic default' ) {
    notify { $config : }
    }

    /etc/puppet/manifests/site.pp
    Sensor::Listener { config => 'asdf' }
    node 'dev' {
    sensor::listner {"test_sensor":}
    }

    This would show 'asdf' for all of your nodes, since the default would
    be set inside site.pp, thus inherited globally.

    Matthias

    Ole Morten Grodås wrote:
    How can I use a variable for setting a default parameter in a defined
    type? The example below illustrates my problem, the $config parameter
    ends up being "undef" while I was expecting it to have the "asdf"
    value. Any comments or suggestions would be appreciated


    /etc/puppet/modules/sensor/manifests/listner.pp
    $myvar="asdf"
    define sensor::listner ( $config = $myvar ) {
    notify { $config : }
    }


    /etc/puppet/manifests/site.pp
    node 'dev' {
    sensor::listner {"test_sensor":}
    }


    root@dev:/home/ole# puppet agent --test
    Info: Retrieving plugin
    Info: Caching catalog for dev
    Info: Applying configuration version '1366464824'
    Notice: undef
    Notice:
    /Stage[main]//Node[dev]/Sensor::Listner[test_sensor]/Notify[undef]/message:
    defined 'message' as 'undef'
    Notice: Finished catalog run in 0.02 seconds
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jcbollinger at Apr 22, 2013 at 2:49 pm

    On Sunday, April 21, 2013 1:37:40 AM UTC-5, Matthias Saou wrote:
    Hi,

    You shouldn't be trying with a variable.


    I'm not sure it's fair to say that. I am a bit surprised that the OP's
    code doesn't work, in fact. Now, I don't think it's a good idea to do it
    that way, but I suppose it's a model for some more complicated thing that
    the OP is planning.

    Some things that might make the example work, either individually or
    jointly, are

    - move the variable declaration to site.pp
    - change the parameter declaration to $config = $::myvar


    Here's what you should
    probably be doing instead :

    /etc/puppet/modules/sensor/manifests/listner.pp
    define sensor::listner ( $config = 'this is the generic default' ) {
    notify { $config : }
    }

    /etc/puppet/manifests/site.pp
    Sensor::Listener { config => 'asdf' }
    node 'dev' {
    sensor::listner {"test_sensor":}
    }

    This would show 'asdf' for all of your nodes, since the default would
    be set inside site.pp, thus inherited globally.
    That's a good solution where it applies, but it does have the limitation
    that it's extrinsic instead of intrinsic.

    If the default needs to be associated with the definition's module, then a
    different approach is needed. Before I suggest other alternatives,
    however, I'd like to know more about the objective. Why does the default
    need to come from a variable? Who is responsible for assigning the
    variable's value (site admin / module dev / computed by Puppet / ...)? To
    what does / should the variable belong (overall site / module / some
    specific class / ...)?


    John

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedApr 20, '13 at 5:22p
activeApr 22, '13 at 2:49p
posts3
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase