That's a fair point, but I shy away from using variables in one class
to influence another as much as possible for two reasons. First is
Puppet's variable scope is confusing at best. Second is I like to have
my classes do actions on a specific bit of a system entirely within
themselves, so anything that does anything with, say, Apache is in an
Apache class and any other class that wants to do something with
Apache has to use the Apache class's defines or sub classes to achieve
that functionality. This doesn't always work out but I try stick to it
as much as possible.

If I had to do something like your example, I would use sub classes of
common that work slightly differently based on the functionality I
want. If that wasn't practical I'd look at trying to achieve the same
thing with a define. This won't work for this exact example as trying
to fill the same file with two different contents is not the smartest
idea, but just to stay on subject I would try to do something like:

#either using a child class
class common {
  file { '/tmp/test':
    content => "default",
    ensure  => file,
  }
}
class common::foo inherits common {
  File['/tmp/test'] { content => "foo content" }
}
class foo {
  include common::foo
}

#or Using a define
class bar {
  include common
  common_file{"something": contents => "bar content" }
}

... but as I said, including both foo and bar on a node in this exact
example would cause compile problems, but hopefully it illustrates my
idea :)

On Dec 17, 4:32 pm, Stefan Schulte <stefan.schu...@taunusstein.net>
wrote:
> On Fri, Dec 17, 2010 at 07:46:29AM -0800, luke.bigum wrote:
> > Nigel's Virtual Resources is one way, this is another using only
> > classes.
>
> > You can put the base software in classes of their own and include
> > these in your 'server classes'. Classes can be included multiple times
> > on a node without causing errors.
>
> Hm personally, I don't really like that because you can include the class in
> different scopes:
>
> One example:
>
>   class common {
>     file { '/tmp/test':
>       content => $tempvar,
>       ensure  => file,
>     }
>   }
>   class foo {
>     $tempvar = "foo"
>     include common
>   }
>   class bar {
>     $tempvar = "bar"
>     include common
>   }
>   node default {
>     include foo
>     include bar
>   }
>
> This does not throw a compile error but it really depends on ordering if
> "foo" or "bar" will be in your file. If you define a virtual resource in
> one place then everything depends on the scope where you defined that
> resource and not where you realize it.
>
> -Stefan
>
>  application_pgp-signature_part
> < 1KViewDownload

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-us...@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