Hi All, Is there a way to override the value of a parameter to a declared class within my base class. My nodes use a base class that occasionally need to be changed. Example: class "base" { class { "apache": mpm => "worker", } ..other awesomeness } Then in the nodes: node "a" { include base } # made up syntax node "specialhost" { class "special" inherits base { Class { "apache": mpm => "prefork" } } } How do I override the mpm param within the apache declaration within the base class for "specialhost"? Is this possible and if not what are the common workarounds? Thanks, Ryan -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ryan Coleman
2012-May-30 20:05 UTC
Re: [Puppet Users] override parameter within base class?
On Wed, May 30, 2012 at 12:37 PM, Ryan Bowlby <rbowlby83@gmail.com> wrote:> Hi All,Hi!> > Is there a way to override the value of a parameter to a declared > class within my base class. My nodes use a base class that > occasionally need to be changed. Example:Yes, there are several ways. One common way is to inherit the class that has the resources you want to modify into a new class and then override the resources. I''d suggest you learn more about that and see if it meets your needs: http://docs.puppetlabs.com/guides/language_guide.html#resource-collections -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nick Fagerlund
2012-May-30 20:16 UTC
[Puppet Users] Re: override parameter within base class?
Probably use a class parameter. You''re gonna want something like this, I think: class base ($kind = "normal") { $mpmtype = $kind ? { ''special'' => ''prefork'', default => ''worker'', } class {''apache'': mpm => $mpmtype } } On your normal nodes, you''d just "include base" or "class {''base'':}", and on your special nodes, you''d "class {''base'': kind => ''special''}". See? Best practice is to try and present a clean interface with your wrapper classes -- that means instead of exposing every knob you might twiddle as a class parameter, settle on a limited number of roles (like that "kind" parameter I was showing), and then use logic inside the class to change any of the relevant bits in the way that node type needs. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/KPQzJv_NjPMJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Gary Larizza
2012-May-30 20:17 UTC
Re: [Puppet Users] override parameter within base class?
On Wed, May 30, 2012 at 12:37 PM, Ryan Bowlby <rbowlby83@gmail.com> wrote:> Hi All, > > Is there a way to override the value of a parameter to a declared > class within my base class. My nodes use a base class that > occasionally need to be changed. Example: > > class "base" { > class { "apache": > mpm => "worker", > } > ..other awesomeness > } > > Then in the nodes: > > node "a" { > include base > } > > # made up syntax > node "specialhost" { > class "special" inherits base { > Class { "apache": mpm => "prefork" } > } > } > > How do I override the mpm param within the apache declaration within > the base class for "specialhost"? Is this possible and if not what are > the common workarounds? > > Thanks, > Ryan > > -- > 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+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >The way Ryan has described will allow you to override parameters FROM a base class inside of a called class. You were asking about overriding parameters from inside the BASE class to a called class? If you''re getting to this level of abstraction, I''d look a data lookup mechanism like Hiera that will allow you to specify different data/parameters based on hierarchy levels of your own design. The benefit of THAT is that you don''t need to use the parameterized class syntax, you can simply do ''include base'' or even ''include apache'' and the parameters to the apache class would always be looked-up to determine the appropriate value per-host. Does that make sense (or help)? -- Gary Larizza Professional Services Engineer Puppet Labs -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-May-30 21:00 UTC
[Puppet Users] Re: override parameter within base class?
On May 30, 2:37 pm, Ryan Bowlby <rbowlb...@gmail.com> wrote:> Hi All, > > Is there a way to override the value of a parameter to a declared > class within my base class. My nodes use a base class that > occasionally need to be changed. Example: > > class "base" { > class { "apache": > mpm => "worker", > } > ..other awesomeness > > } > > Then in the nodes: > > node "a" { > include base > > } > > # made up syntax > node "specialhost" { > class "special" inherits base { > Class { "apache": mpm => "prefork" } > } > > } > > How do I override the mpm param within the apache declaration within > the base class for "specialhost"? Is this possible and if not what are > the common workarounds?What you wrote is similar to what I would expect to work, which would be this: class special inherits base { Class[''apache''] { mpm => ''prefork'' } } node ''specialhost'' { include ''special'' } That''s the standard syntax for subclasses overriding their parent class''s resource''s parameters. In practice, I''d put the subclass definition in its own file in a suitable module, of course. 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ryan Bowlby
2012-Jun-02 02:44 UTC
[Puppet Users] Re: override parameter within base class?
Thanks John, but it appears the ability to override a parent class parameter is limited to the resources DEFINED within that class. In my base class I am merely declaring/instantiating the apache class and not defining it. The overriding of parameters does not appear to work in that case. I ended up just doing a few simple wrapper parameters as advised by Nick. I like the Hiera idea but it will have to wait since we have so much low hanging fruit to pick for the time being. Thanks everyone! -Ryan On May 30, 2:00 pm, jcbollinger <John.Bollin...@stJude.org> wrote:> On May 30, 2:37 pm, Ryan Bowlby <rbowlb...@gmail.com> wrote: > > > > > > > > > > > Hi All, > > > Is there a way to override the value of a parameter to a declared > > class within my base class. My nodes use a base class that > > occasionally need to be changed. Example: > > > class "base" { > > class { "apache": > > mpm => "worker", > > } > > ..other awesomeness > > > } > > > Then in the nodes: > > > node "a" { > > include base > > > } > > > # made up syntax > > node "specialhost" { > > class "special" inherits base { > > Class { "apache": mpm => "prefork" } > > } > > > } > > > How do I override the mpm param within the apache declaration within > > the base class for "specialhost"? Is this possible and if not what are > > the common workarounds? > > What you wrote is similar to what I would expect to work, which would > be this: > > class special inherits base { > Class[''apache''] { mpm => ''prefork'' } > > } > > node ''specialhost'' { > include ''special'' > > } > > That''s the standard syntax for subclasses overriding their parent > class''s resource''s parameters. In practice, I''d put the subclass > definition in its own file in a suitable module, of course. > > 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Jun-04 13:17 UTC
[Puppet Users] Re: override parameter within base class?
On Jun 1, 9:44 pm, Ryan Bowlby <rbowlb...@gmail.com> wrote:> Thanks John, but it appears the ability to override a parent class > parameter is limited to the resources DEFINED within that class.Subclasses can override only parameters of resources *declared* by their parent classes. And that''s exactly what I suggested you try, relying on Puppet''s rather blurry distinction between classes and resources. Specifically, class "base" declares the resource Class[''apache''], and I suggested that subclass "special" override one of the parameters that base declares for that resource.> In my > base class I am merely declaring/instantiating the apache class and > not defining it.And that''s the case for most resources. With any resource other than a class, a subclass of the declaring class can override that resource''s parameters. Indeed, few resources (including classes) are *defined* inside other classes at all, but that doesn''t prevent their parameters from being overridden.> The overriding of parameters does not appear to work > in that case.But of course, that''s the bottom line. I find it slightly surprising, considering how much Puppetlabs has tried to make classes a special variety of resources, but not shocking. I''m sorry it turned out to be a red herring.> I ended up just doing a few simple wrapper parameters as advised by > Nick. I like the Hiera idea but it will have to wait since we have so > much low hanging fruit to pick for the time being. Thanks everyone!I''m glad you found something that works for you. Cheers, 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.