Re: [Puppet Users] Depending on a class from a class?

Patrick
2010-11-30T17:59:15Z

On Nov 30, 2010, at 7:03 AM, Daniel Piddock wrote:

> Hello,
>
> I fear that I have done something stupid in my manifests that requires
> a redesign. To take an example:
>
> I have the global statement:
> Package {
>  ensure  => latest,
>  require => Class[''repositories''],
> }
>
> I then have a repositories module with init.pp containing:
> class repositories {
>  case $operatingsystem {
>    debian: {
>      include repositories::debian
>    }
>    fedora: {
>      include repositories::fedora
>    }
>    default: {
>      fail "Unsupported OS $operatingsystem''"
>    }
>  }
> }
>
> Unfortunately I was hoping that an include here would act like a
> requirement, however it does not. The contents of debian.pp/fedora.pp
> get evaluated at an arbitrary later point causing interesting issues
> when first installing a system. Puppet attempts to install some
> packages before the repositories have been configured.
>
> Is there any way for a class to depend on another class or for the
> include statement to act more like a require?
>
> In this example it would be trivial to change the global statement to
> directly require the operating system''s repositories subclass.
> Unfortunately I have used this paradigm in multiple locations, some
> where the alternative may not be as obvious or would increase the
> verbosity of the including classes.
>
> Thank you for any pointers,

I think this will work, but I don''t have a machine to test the syntax
on right now:

include repositories
Package {
 ensure  => latest,
 require => Class[''repositories''],
}



class repositories {

 case $operatingsystem {
   debian: {
     $repositoryclass
   }
   fedora: {
     $repositoryclass
   }
   default: {
     fail "Unsupported OS $operatingsystem''"
   }
 }

 require( Class[ $repositoryclass ] )

}