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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to