Mixing up classes?

21 views
Skip to first unread message

Jakov Sosic

unread,
Sep 7, 2012, 9:02:29 AM9/7/12
to Puppet Users
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?
Where can I find examples?

Or, if I use postgresql class to manage PgSQL, how can add a database
from some class that needs to create PgSQL database?


ty.


Ps. I can elaborate more if question is not clear enough...

jcbollinger

unread,
Sep 10, 2012, 10:25:56 AM9/10/12
to puppet...@googlegroups.com


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

Reply all
Reply to author
Forward
0 new messages