Pro Puppet

Free Pro Puppet by Jeffrey McCune James Turnbull Page B

Book: Pro Puppet by Jeffrey McCune James Turnbull Read Free Book Online
Authors: Jeffrey McCune James Turnbull
systems.
    postfix
postfix/files/master.cf
postifx/manifests/init.pp
postfix/manifests/install.pp
postfix/manifests/config.pp
postfix/manifests/service.pp
postfix/templates/main.cf.erb
The postfix::install class
    We also have some similar resources present in our Postfix module that we saw in our SSH module, for example in the
postfix::install
class we install two packages,
postfix
and
mailx
:
    class postfix::install {
  package { [ "postfix", "mailx" ]:
    ensure => present,
  }
}
    Note that we’ve used an array to specify both packages in a single resource statement this is a useful shortcut that allows you specify multiple items in a single resource.
The postfix::config class
    Next, we have the
postfix::config
class, which we will use to configure our Postfix server.
    class postfix::config {
  File {
    owner => "postfix",
    group => "postfix",
    mode => 0644,
  }

  file { "/etc/postfix/master.cf":
    ensure = > present,
    source => "puppet:///modules/postfix/master.cf",
    require => Class["postfix::install"],
    notify => Class["postfix::service"],
  }

  file { "/etc/postfix/main.cf":
    ensure = > present,
    content => template("postfix/main.cf.erb"),
    require => Class["postfix::install"],
    notify => Class["postfix::service"],
  }
}
    You may have noticed some new syntax: We specified the File resource type capitalized and without a title. This syntax is called a resource default, and it allows us to specify defaults for a particular resource type. In this case, all File resources within the
postfix::config
class will be owned by the user
postfix
, the group
postfix
and with a mode of
0644
. Resource defaults only apply to the current scope, but you can apply global defaults by specifying them in your
site.pp
file.
    A common use for global defaults is to define a global “filebucket” for backing up the files Puppet changes. You can see the filebucket type and an example of how to use it globally at
http://docs.puppetlabs.com/references/stable/type.html#filebucket .
    Tip A common use for global defaults is to define a global “filebucket” for backing up the files Puppet changes. You can see the filebucket type and an example of how to use it globally at
http://docs.puppetlabs.com/references/stable/type.html#filebucket
.
    METAPARAMETER DEFAULTS
    Like resource defaults, you can also set defaults for metaparameters, such as
require
, using Puppet variable syntax. For example:
    class postfix::config {
  $require = Class["postfix::install"]
  …
}
    This would set a default for the
require
metaparameter in the
postfix::config
class and means we could remove all the
require => Class["postfix::install"]
statements from our resources in that class.
    We’ve also introduced a new attribute in our
File["/etc/postfix/main.cf"]
resource –
content
. We’ve already seen the
source
attribute, which allows Puppet to serve out files, and we’ve used it in one of our File resources,
File["/etc/postfix/master.cf"]
. The
content
attribute allows us to specify the content of the file resources as a string. But it also allows us to specify a template for our file. The template is specified using a function called
template
.
    As previously mentioned, functions are commands that run on the Puppet master and return values or results. In this case, the
template
function allows us to specify a Ruby ERB template (
http://ruby-doc.org/stdlib/libdoc/erb/rdoc/
), from which we can create the templated content for our configuration file. We specify the template like this:
        content => template("postfix/main.cf.erb"),
    We’ve specified the name of the function, “template,” and inside brackets the name of the module that contains the template and the name of the template file. Puppet knows when we specify the name of the module to look inside the
postfix/templates
directory for the requisite file – here,
main.cf.erb
.
    THE REQUIRE FUNCTION
    In

Similar Books

Skin Walkers - King

Susan Bliler

A Wild Ride

Andrew Grey

The Safest Place

Suzanne Bugler

Women and Men

Joseph McElroy

Chance on Love

Vristen Pierce

Valley Thieves

Max Brand