On Wed, May 16, 2012 at 6:11 AM, Rufus McDufus <r...@bamalam.com> wrote:
> In the Puppet Enterprise docs below, they mention using a 'Site
> Module'
>
> http://docs.puppetlabs.com/pe/2.5/quick_writing.html#using-a-site-module
>
> However I can't find any examples of people using such a method. I'm
> interested in this because I'd prefer to use generic modules (e.g from
> puppet forge etc) as 'libraries' without modifying the modules, but
> call the modules elsewhere & perform the site-specific logic outside
> of the generic modules.
> How would a site module differ from a manifest and what would be the
> advantage of a site module instead of doing it in manifests?

Site modules are usually private to an organization which is why there
might not be many published examples of them.

Writing a module that support the "site module" pattern is a bit
trickier but here's the most common use case I've found.  A module
that is generally re-usable should use it's own template for the
general case but allow the module user to pass in a different template
from a different module.  This "different module" is the site module.

So, how do I change the behavior of a module without modifying the
module itself?  If it allows you to pass in the data you need then you
can store that data in a site module and pass it using the template
function:

# motd module:
class motd($motd_content='UNSET') {
  $motd_content_real = $motd_content ? {
    UNSET => template("motd/motd.erb"),
    default => $motd_content,
  }

  # Manage the message of the day
  file { "/etc/motd":
    content => $motd_content_real,
  }
}

Now there are two ways to use this module.  If I don't want to change
the behavior I can just use it "as is"

node default { include motd }

However, if I want to change the message of the day I can pass in the
full contents from my own module rather than modifying the motd module
itself:

node default {
  class { motd: motd_content => template('site/motd.erb') }
}

This will cause the motd module to use a template from my site module
rather than using it's own erb template.  The key difference is
template("motd/motd.erb") inside the motd module versus
template("site/motd.erb") "outside" the motd module.

Hope this helps,
-Jeff

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