John Morrissey
2011-Sep-22 13:53 UTC
[Puppet Users] Passing additional dependencies into a class
I''m using an Apache 2 base class based on http://projects.puppetlabs.com/projects/1/wiki/Debian_Apache2_Recipe_Patterns. I''d like to pass additional dependencies to the class and/or the definitions it contains. For example, I''d like to allow classes using this Apache base class to add additional require items to Service[''apache2'']. I could pass the dependency list to the class, like so: class apache2($require) { service { ''apache2'': require => $require, } } class { ''apache2'': require => [Package[''foo''], Package[''bar'']], } but this requires apache2 consumers to pass the entire dependency list; the apache2 base class can''t inject its own dependencies transparently. I''d like the passed dependencies to be *in addition to* any dependencies the apache2 base class demands. Is there a sane way to do this? john -- John Morrissey _o /\ ---- __o jwm@horde.net _-< \_ / \ ---- < \, www.horde.net/ __(_)/_(_)________/ \_______(_) /_(_)__ -- 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.
Robin Lee Powell
2011-Sep-22 17:54 UTC
Re: [Puppet Users] Passing additional dependencies into a class
On Thu, Sep 22, 2011 at 09:53:46AM -0400, John Morrissey wrote:> I''m using an Apache 2 base class based on > http://projects.puppetlabs.com/projects/1/wiki/Debian_Apache2_Recipe_Patterns. > > I''d like to pass additional dependencies to the class and/or the definitions > it contains. For example, I''d like to allow classes using this Apache base > class to add additional require items to Service[''apache2'']. > > I could pass the dependency list to the class, like so: > > class apache2($require) { > service { ''apache2'': > require => $require, > } > } > class { ''apache2'': > require => [Package[''foo''], Package[''bar'']], > } > > but this requires apache2 consumers to pass the entire dependency list; the > apache2 base class can''t inject its own dependencies transparently. I''d like > the passed dependencies to be *in addition to* any dependencies the apache2 > base class demands. > > Is there a sane way to do this?I *believe* this will work: class apache2($extra_requires) { service { ''apache2'': require => [Service[''foo''], $extra_requires], } } class { ''apache2'': extra_requires => [Package[''foo''], Package[''bar'']], } But I have not tested it. -Robin -- http://singinst.org/ : Our last, best hope for a fantastic future. Lojban (http://www.lojban.org/): The language in which "this parrot is dead" is "ti poi spitaki cu morsi", but "this sentence is false" is "na nei". My personal page: http://www.digitalkingdom.org/rlp/ -- 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
2011-Sep-22 20:11 UTC
[Puppet Users] Re: Passing additional dependencies into a class
On Sep 22, 12:54 pm, Robin Lee Powell <rlpow...@digitalkingdom.org> wrote:> On Thu, Sep 22, 2011 at 09:53:46AM -0400, John Morrissey wrote: > > I''m using an Apache 2 base class based on > >http://projects.puppetlabs.com/projects/1/wiki/Debian_Apache2_Recipe_.... > > > I''d like to pass additional dependencies to the class and/or the definitions > > it contains. For example, I''d like to allow classes using this Apache base > > class to add additional require items to Service[''apache2'']. > > > I could pass the dependency list to the class, like so: > > > class apache2($require) { > > service { ''apache2'': > > require => $require, > > } > > } > > class { ''apache2'': > > require => [Package[''foo''], Package[''bar'']], > > } > > > but this requires apache2 consumers to pass the entire dependency list; the > > apache2 base class can''t inject its own dependencies transparently. I''d like > > the passed dependencies to be *in addition to* any dependencies the apache2 > > base class demands. > > > Is there a sane way to do this? > > I *believe* this will work: > > class apache2($extra_requires) { > service { ''apache2'': > require => [Service[''foo''], $extra_requires], > }} > > class { ''apache2'': > extra_requires => [Package[''foo''], Package[''bar'']], > > } > > But I have not tested it.I do not know whether that works, but I would not personally feel comfortable assuming that it would continue to work from one version of Puppet to another. I think this is rather a quirky question in the first place. Generally one wants to write classes that are fairly self-contained, and modules that are as much as possible self-contained. Among other things, that implies that classes ought to know their own requirements rather than having to be told them. A better solution than passing dependencies into a class might be class-level dependencies. For example, if you have a Foo resource that must be applied before all of the resources of class apache2, then declare the dependency from that side via the "before" metaparameter: foo { "my_foo": # various properties... before => Class[''apache2''] # note: that class should be in a module, and # referred to by its fully-qualified name } Alternatively, if all the resources in Class[''foo_class''] should be applied before any of those in Class[''apache2''], then you can describe that to Puppet by putting Class[''foo_class''] -> Class[''apache2''] somewhere outside either one. 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.
John Morrissey
2011-Sep-30 20:04 UTC
[Puppet Users] Re: Passing additional dependencies into a class
On Thu, Sep 22, 2011 at 01:11:28PM -0700, jcbollinger wrote:> On Sep 22, 12:54 pm, Robin Lee Powell <rlpow...@digitalkingdom.org> > wrote: > > On Thu, Sep 22, 2011 at 09:53:46AM -0400, John Morrissey wrote: > > > I''m using an Apache 2 base class based on > > >http://projects.puppetlabs.com/projects/1/wiki/Debian_Apache2_Recipe_.... > > > > > I''d like to pass additional dependencies to the class and/or the > > > definitions it contains. For example, I''d like to allow classes using > > > this Apache base class to add additional require items to > > > Service[''apache2''].[snip]> > > but this requires apache2 consumers to pass the entire dependency list; the > > > apache2 base class can''t inject its own dependencies transparently. I''d like > > > the passed dependencies to be *in addition to* any dependencies the apache2 > > > base class demands. > > > > I *believe* this will work: > > > > class apache2($extra_requires) { > > service { ''apache2'': > > require => [Service[''foo''], $extra_requires], > > }} > > > > class { ''apache2'': > > extra_requires => [Package[''foo''], Package[''bar'']], > > > > } > > > > But I have not tested it. > > I do not know whether that works, but I would not personally feel > comfortable assuming that it would continue to work from one version > of Puppet to another.nod, the semantics that implies sketches me out a little bit.> I think this is rather a quirky question in the first place. > Generally one wants to write classes that are fairly self-contained, > and modules that are as much as possible self-contained. Among other > things, that implies that classes ought to know their own requirements > rather than having to be told them.The base class is self contained, but the depending class has resources that modify the base class'' behavior in such a way that I''d prefer that those resources be in place before the service resource is processed. I''m probably nit picking in this case, though.> A better solution than passing dependencies into a class might be > class-level dependencies. For example, if you have a Foo resource > that must be applied before all of the resources of class apache2, > then declare the dependency from that side via the "before" > metaparameter: > > foo { "my_foo": > # various properties... > > before => Class[''apache2''] > # note: that class should be in a module, and > # referred to by its fully-qualified name > }ach, I always forget about ''before''. That''ll work just fine. Thanks. john -- John Morrissey _o /\ ---- __o jwm@horde.net _-< \_ / \ ---- < \, www.horde.net/ __(_)/_(_)________/ \_______(_) /_(_)__ -- 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.