Cesar Covarrubias
2013-Mar-26 02:14 UTC
[Puppet Users] Reassigning value of class declared in templates file
I am trying to create a "template" for all my servers. I have 2 configurations. An NTP client (which is taken care of in the baseclass class. I want to create an override specific for the NTP servers by declaring something specific in the node declaration. Something like "baseclass::ntp:restrict => true,". Or alternatively, how would I change one of the already declared variable from baseclass::ntp? Does anyone have any ideas host to do this? This is what I have so far: templates.pp class baseclass { include defaultusers include sudoers include issue class { ntp: ensure => running, servers => [''ntpserver1.host.com'', ''ntpserver2.host.com'',], autoupdate => false, } } nodes.pp node default { include baseclass } node "ntpserver1.host.com" inherits default { <some code here to declare new variable in baseclass::ntp> <some code here to change existing variable, such as "ensure"> } -- 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.
Sergio Jimenez
2013-Mar-26 12:02 UTC
[Puppet Users] Re: Reassigning value of class declared in templates file
Not really sure about it (pretty new in puppet) but ... what about parametrized classes? You could define default values for parameters in the class or overwrite them when using the class. sjr. On Tuesday, March 26, 2013 3:14:51 AM UTC+1, Cesar Covarrubias wrote:> > I am trying to create a "template" for all my servers. I have 2 > configurations. An NTP client (which is taken care of in the baseclass > class. I want to create an override specific for the NTP servers by > declaring something specific in the node declaration. Something like > "baseclass::ntp:restrict => true,". Or alternatively, how would I change > one of the already declared variable from baseclass::ntp? > > Does anyone have any ideas host to do this? > > This is what I have so far: > > templates.pp > > class baseclass { > include defaultusers > include sudoers > include issue > > class { ntp: > ensure => running, > servers => [''ntpserver1.host.com'', > ''ntpserver2.host.com'',], > autoupdate => false, > } > } > > > > > nodes.pp > > node default { > include baseclass > } > > node "ntpserver1.host.com" inherits default { > <some code here to declare new variable in baseclass::ntp> > <some code here to change existing variable, such as "ensure"> > } > >-- 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.
Peter Meier
2013-Mar-26 12:34 UTC
Re: [Puppet Users] Reassigning value of class declared in templates file
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1> Does anyone have any ideas host to do this?Do not use node inheritance, simply don''t - it will hurt you badly at some point. It does not work in the same way as class inheritance does. And also class inheritance should not used that widely (more or less only if you need to overwrite values for resources, that aren''t assignable as parameter from an external source. Instead use hiera and design your hierarchy there, then you will have much more flexibility. ~pete -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlFRldgACgkQbwltcAfKi38a0wCeLmJwcsPkEdHBjK2eO1zehXRD k2sAoKxQgEy95TR4ExAPjNUVCQiTEQyD =WmAP -----END PGP SIGNATURE----- -- 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
2013-Mar-26 13:50 UTC
[Puppet Users] Re: Reassigning value of class declared in templates file
On Monday, March 25, 2013 9:14:51 PM UTC-5, Cesar Covarrubias wrote:> > I am trying to create a "template" for all my servers. I have 2 > configurations. An NTP client (which is taken care of in the baseclass > class. I want to create an override specific for the NTP servers by > declaring something specific in the node declaration. Something like > "baseclass::ntp:restrict => true,". Or alternatively, how would I change > one of the already declared variable from baseclass::ntp? > > Does anyone have any ideas host to do this? > > This is what I have so far: > > templates.pp > > class baseclass { > include defaultusers > include sudoers > include issue > > class { ntp: > ensure => running, > servers => [''ntpserver1.host.com'', > ''ntpserver2.host.com'',], > autoupdate => false, > } > } > > > > > nodes.pp > > node default { > include baseclass > } > > node "ntpserver1.host.com" inherits default { > <some code here to declare new variable in baseclass::ntp> > <some code here to change existing variable, such as "ensure"> > } > >I don''t have any objection to node inheritance, though I do recommend keeping node inheritance trees very shallow -- two levels, preferably, or three as an absolute, special-case maximum. You also need to understand what it means. Specifically, it really does mean NODE inheritance. The inheriting node does not get the inherited node''s declarations directly, but rather the whole node, with its own, separate scope. The inherited node''s declarations will be parsed and interpreted independently of any inheriting nodes that may be in play. Inheriting nodes can only add their own declarations on top. There is a syntax for resource parameter override, but it does not work for classes (and though there are efforts underway to improve that, it *cannot*work for classes under some circumstances). Your inheriting node therefore cannot operate as you hoped. The best solution is probably for your class to draw its data from hiera, so that you can use your hiera hierarchy to provide different parameters in the first place based on the nature of the client being configured. Alternatively, the old-school way to do this is to use class inheritance. In fact, it is precisely what class inheritance is meant for. The inheritance approach would involve creating a subclass of ntp, say ntp::server, which applies appropriate overrides to the parameters of resources declared by its parent class. You then declare the subclass (also or instead) to the nodes that should be NTP servers. Consult the language docs for details. 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.
jcbollinger
2013-Mar-27 13:04 UTC
[Puppet Users] Re: Reassigning value of class declared in templates file
On Tuesday, March 26, 2013 7:02:34 AM UTC-5, Sergio Jimenez wrote:> > > Not really sure about it (pretty new in puppet) but ... what about > parametrized classes? You could define default values for parameters in the > class or overwrite them when using the class. > >If you look at his code, you will see that he is already using a parameterized class. His question is about overriding parameter values he has already declared for that class. Speaking of parameterized classes, by the way, they should not be used as base classes in class inheritance, so converting to an old-school approach based on class inheritance would require changing the parameterized class to a normal one. Not much of a loss, really, but just saying. 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.