On Oct 7, 6:05 am, Arnau Bria <arnaub...@pic.es> wrote:
> Hi all,
>
> I think I'm not understanding something...
>
> fromhttp://docs.puppetlabs.com/guides/parameterized_classes.html:
>
> "The parameters you name can be used as normal local variables
> throughout the class definition"
>
> so, I have a class like:
>
> class common::nrpe($ensure='absent') {
> [...]
>
> if ($::kernel=='Linux') and ($::lsbmajdistrelease=='6') {
>         $ensure='present'
>
> }
>
> so, by default the class is dissabled, but if it's a Linux release 6,
> the value must be present.
>
> so, I define the class in a Linux release 6 like:
>
> nodes 'test' {
>         class { 'common::nrpe' : }
>
> }
>
> pupet fails with error:
>
> Cannot reassign variable ensure
>
> So, what am I missunderstanding? What is the correct way for doing what
> I'm trying?


You are misunderstanding that Puppet variables' values can never be
reassigned.  Once a variable has a value, it never changes throughout
the compilation of that catalog.  This is an aspect of Puppet DSL's
declarative nature.

As to how to accomplish what you ask, the usual way would be to use
the parameter and any other data you want to select the value of a
*different* variable, and then use that second variable.  The same
thing is fairly common practice in defined types:

class common::nrpe($ensure='absent') {
[...]

if ($::kernel=='Linux') and ($::lsbmajdistrelease=='6') {
  $really_ensure = 'present'
} else {
  $really_ensure = $ensure
}

[...]

}

While I'm on this topic, I'll throw in that I would find it terribly
confusing if a class or definition failed to honor my specification
for a parameter named 'ensure'.  I'd also find it confusing, though
less so, for the default value of an 'ensure' parameter to be
'absent'.  I recommend that you tweak your design a bit so as to not
leave little traps like those for yourself and others to stumble over
later.  Or at least document the wazoo out of that thing.


John

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

Reply via email to