Re: [Puppet Users] Is there a way to invoke a template from multiple modules?

Phillip Frost
Thu, 01 Dec 2011 16:15:41 -0000

On Dec 1, 2011, at 10:49 AM, Peter Berghold wrote:

> I have a module called "postfix" which handles the installation
and base configuration of the postfix MTA.  I have another module called
"spamassassin" which deals with the download and installation of the
Mail::SpamAssassin Perl module which incidently adds the init scripts for
SpamAssassin and the clamd binary.
>
> I''d like that spamassassin module to modify both the master.cf and
main.cf file of postfix to enable its own functionality.
> [...]

Don''t have the spamassassin module modify postfix configuration.
Rather, provide in the postfix module a resource that adds bits to the postfix
configuration, and use it from the spamassassin module.

This is a common pattern:

class sharedsystem {
  package { ''sharedsystem'': ensure => installed }
  service { ''sharedsystem'': ensure => running }
}

define sharedsystem::config ($source) {
  file { "/etc/sharedsystem/config.d/$name": source => $source,
notify => Service[''sharedsystem''] }
}

class subsystem1 {
  package { ''subsystem1'': ensure => installed }
  sharedsystem::config { ''subsystem1'': source =>
"puppet:///modules/subsystem1/sharedsystem.conf" }
}

class subsystem2 {
  package { ''subsystem2'': ensure => installed }
  sharedsystem::config { ''subsystem1'': source =>
"puppet:///modules/subsystem2/sharedsystem.conf" }
}

By defining sharedsystem::config, you expose from the sharedsystem module a way
for other modules to configure sharedsystem, without exposing unnecessary
details, and avoiding conflicts. The trick, of course, is finding a way to break
down bits of configuration into non-conflicting resources. If your sharedsystem
supports a configuration directory (/etc/apache/sites-enabled,
/etc/apt/sources.list.d, /etc/sudoers.d, etc) then it''s easy. If not,
then maybe you use something like puppet-concat to concatenate your
configuration bits into one file.