[Puppet Users] Re: how to modify a parameter inside a parametrized class

2011-10-07 Thread jcbollinger


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.



Re: [Puppet Users] Re: how to modify a parameter inside a parametrized class

2011-10-07 Thread Arnau Bria
On Fri, 7 Oct 2011 05:55:34 -0700 (PDT)
jcbollinger jcbollinger wrote:

Hi John,

 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
 }
 
 [...]
 
 }

Ok, I solved the issue with something like that but I thought it was
some kind of ugly workaround... but if it's common I feel better with my
code.


 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'.  

Sorry John, but I don't understand this point.

 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.

I'm playing with this class. First time I do something like above.
Our production services have a default present, but this one is still
in test and I'd like to test it only on Linux 6., so I was playing with
logic inside new class :-)
 
 John
Many thanks for your reply,
Arnau

-- 
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.



[Puppet Users] Re: how to modify a parameter inside a parametrized class

2011-10-07 Thread jcbollinger


On Oct 7, 8:11 am, Arnau Bria arnaub...@pic.es wrote:
 On Fri, 7 Oct 2011 05:55:34 -0700 (PDT)

 jcbollinger jcbollinger wrote:
  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'.  

 Sorry John, but I don't understand this point.

Because of the consistent manner of ensure parameters' use in
Puppet's built-in resources, and the associated conventions even for
custom and defined types, I would be very surprised if I ever declared
something with ensure = 'absent' but that specification was
overridden to the opposite.  Indeed, I would be at least somewhat
surprised by that with *any* parameter.  Don't give me the option if
you don't intend to honor it.

Inasmuch as this is for testing purposes, however, that's a different
story.  I don't think I would test in the way you are doing, but then
again, maybe I would.


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.



Re: [Puppet Users] Re: how to modify a parameter inside a parametrized class

2011-10-07 Thread Arnau Bria
On Fri, 7 Oct 2011 06:34:00 -0700 (PDT)
jcbollinger jcbollinger wrote:

 On Oct 7, 8:11 am, Arnau Bria arnaub...@pic.es wrote:
  On Fri, 7 Oct 2011 05:55:34 -0700 (PDT)
 
  jcbollinger jcbollinger wrote:
   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'.  
 
  Sorry John, but I don't understand this point.
 
 Because of the consistent manner of ensure parameters' use in
 Puppet's built-in resources, and the associated conventions even for
 custom and defined types, I would be very surprised if I ever declared
 something with ensure = 'absent' but that specification was
 overridden to the opposite.  Indeed, I would be at least somewhat
 surprised by that with *any* parameter.  Don't give me the option if
 you don't intend to honor it.

Ok, now it's clear.
I should put that logic outside the class, in node/param definitions ..
something like:

if ($::kernel=='Linux') and ($::lsbmajdistrelease=='6') {
class { 'common::nrpe' :
ensure = absnet,
}else{
class { 'common::nrpe' :
ensure = present,
}

 
 Inasmuch as this is for testing purposes, however, that's a different
 story.  I don't think I would test in the way you are doing, but then
 again, maybe I would.

 
 John
 
Many thanks for your reply,
Arnau

-- 
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.