On Friday, September 7, 2012 8:02:50 AM UTC-5, Jakov Sosic wrote:
Hi.
What is the best way to mix classes?
For example, I have a class apache, which sets up web server, and have
class cobbler which needs to add few files to /etc/httpd/conf.d.
What's the best way to do this? Include apache class in cobbler class?
That is what I would do, provided that class 'apache' is not parametrized. I.e.:
class cobbler {
include 'apache'
# ...
}
Unfortunately, that approach doesn't work well if class 'apache' is parametrized. If class 'apache' is parametrized, or if for some reason you don't want to make the module containing your cobbler class explicitly dependent on the module containing class 'apache', then you can declare the dependency externally via Puppet's chaining operators:
class { 'apache':
# some parameters
}
include 'cobbler'
Class['apache'] -> Class['cobbler']
You can also set up finer-grained relationships between classes and individual resources, or between pairs of resources, using the 'before' and 'requires' metaparameters, including across class and even module boundaries, but that kind of deep coupling can present a maintenance problem.
John