I've solved the identical problem using defines instead of classes. I
know that hiera can be a better solution, but I'm waiting for next
major release to adopt hiera.
I've a generic nrpe::check define: each check is a define that use
this generic definition, so my check_load.pp in nrpe module is
define nrpe::check_load(
$warn1=8,
$warn5=4,
$warn15=2,
$crit1=20,
$crit5=10,
$crit15=5,
)
{
if ! is_numeric($warn1)
{
fail('Variable warn1 must be numeric')
}
if ! is_numeric($warn5)
{
fail('Variable warn5 must be numeric')
}
if ! is_numeric($warn15)
{
fail('Variable warn15 must be numeric')
}
if ! is_numeric($crit1)
{
fail('Variable crit1 must be numeric')
}
if ! is_numeric($crit5)
{
fail('Variable crit5 must be numeric')
}
if ! is_numeric($crit15)
{
fail('Variable crit15 must be numeric')
}
# -r plugin option make it compatible with multi-core cpu
nrpe::check{ 'load':
params => "-r -w ${warn1},${warn5},${warn15} -c
${crit1},${crit5},${crit15}"
}
}
In generic_host I create a resource with no parameters, so defaults apply:
nrpe::check_load { 'load': }
If I've a node with a medium greater load than my default I do:
node 'node-with-high-load' inherits generic_host {
Nrpe::Check_load['load']{ warn5 => 20 }
}
Hopes this helps,
L
2012/9/25 George Shammas <[email protected]>:
> Hi John,
>
> Thanks for the response. They variables are only used in the template, as
> the NRPE daemon is manged by flat files. I will do some research into hiera.
>
> --George
>
> On Tuesday, September 25, 2012 11:28:31 AM UTC-4, jcbollinger wrote:
>>
>>
>>
>> On Monday, September 24, 2012 11:47:31 AM UTC-5, George Shammas wrote:
>>>
>>> I am trying to override variables in a class that is defined in the
>>> default node profile. I want parent class to be included in every single
>>> node, but override its variables in others. I have tried it several
>>> different ways now, and every single time the variables either become unset
>>> (undefined) or are set to the value of the first if statement.
>>
>>
>> You cannot override class variables. You especially cannot override class
>> parameters. You can override only resource properties (and classes are not
>> resources, appearances notwithstanding).
>>
>> Moreover, subclasses do not set parameters for their parent classes, even
>> if they themselves have parameters of the same names. Therefore, it is
>> usually a bad idea to inherit from a parametrized class (in fact, the v 2.7
>> docs say it's not supported). If you do so, then you must explicitly
>> declare the parent class on every node for which you want to set non-default
>> parameters, whether or not you also declare the child class.
>>
>> Since you don't actually use the variables in question in your example, I
>> can't guess what your larger purpose may be, therefore it is difficult for
>> me to advise you. Nevertheless, at the low level we are focused on, you can
>> achieve something similar to what you have asked by employing a data
>> hierarchy instead of a class hierarchy. That is what the Hiera module is
>> all about. Since hiera will be integrated into Puppet 3, getting started
>> with it now is also forward-looking.
>>
>> Once you install hiera and set up your data, the Puppet side could be as
>> simple as this:
>>
>> class nrpe::load { # no parameters
>> package { 'nagios-plugins-load': ensure => installed }
>>
>> $warn_real = hiera('nrpe::warn')
>> $crit_real = hiera('nrpe::crit')
>>
>> # alternatively, load $warn and $crit via hiera,
>> # and retain the original logic for setting
>> # $warn_real and $crit_real
>>
>> file { "/etc/nagios/command.d/load.cfg":
>> owner => root,
>> group => root,
>> mode => 640,
>> content => template("nrpe/load.cfg.erb"),
>> notify => Service[nrpe]
>> }
>> }
>>
>> node "somenode.tld" inherits basenode {
>> # no subclass involved
>> }
>>
>>
>> John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.