Pulling Strings With Puppet - James Turnbull [40]
In Listing 4-4, you'll also see that we included the mysgl module in our templates. pp file as part of the dbserver template node.
Postfix Module
Our next module will install and manage a Postfix mail server. The structure of our Postfix module can be seen here:
We've specified an init. pp file, a definition, and three configuration files in the postfix module. Like the mysql module, we've included all required configuration in the init. pp file, barring a single definition that we've placed in the postfix_files . pp file. You can see the contents of the init. pp file in Listing 4-17.
In Listing 4-17, we've defined a class called postf ix. Inside the class, we've defined a number of resources and two variables. The first variable, $mailadmin, defines the mail administrator for our nodes; it makes use of the $domain fact to populate this attribute. The second variable is an array of packages to be loaded. The package listing takes advantage of another fact, $architecture, to ensure that the right package for each node is loaded.
Then we've defined some resources to manage our Postfix configuration. We first install the postfix and postfix-pflogsumm packages. Next, we retrieve our three configuration files from our file server. To do this, we use the definition we've created. The definition is a shortcut that populates most of the required attributes for our file resource type. The postfix:: postfix_files definition can be seen in Listing 4-18.
The postfix:: postfix_files definition is very simple. It specifies some defaults for each file specified to the definition, uses the require attribute to ensure the postf ix package is installed prior to the file, and uses the value passed from the source attribute when the definition is invoked to specify where to retrieve the file from.
Then we enable and ensure that the Postfix services are started. Lastly, we add a cron job that enables pflogsumm reports to be generated and sent. We use the $fqdn fact and our $mailadmin variable in our cron job.
Note - Throughout the module, we've also made use of the require attribute to ensure that all our resources are processed in a logical order.
Again, in Listing 4-4, you'll see that we have included the postf ix module in our templates. pp file as part of the mailserver template node.
Apache Module
The last module we're going to create is the apache module that will install and manage the Apache web server. The structure of our Apache module can be seen here:
We've defined an init.pp file; a file called virtual_host.pp, which contains a definition that will allow us to create virtual hosts; and the apache_files. pp file, which contains the apache::apache_files class that provides some file management shortcuts, much like the postfix::postfix_files class in the postf ix module. We also create the httpd.conf configuration file in the files directory and finally a template for our virtual hosts in a file called virtual_host.erbin the templates directory.
Let's start by looking at the init. pp file that contains the core configuration for the module in Listing 4-19.
Listing 4-19 defines the apache class that installs our required Apache packages, installs the httpd.conf configuration file, and then ensures the httpd service is started and running. You'll also notice we've specified the hasrestart and hasstatus attributes on the service. This tells Puppet that the init script for the service supports the restart and status commands. This lets Puppet know that the init script has more functionality and makes interacting with the script more flexible.
Next, in Listing 4-20, you'll find the apache: :apache_f lies definition, which provides some shortcuts to manage our Apache-related files.
Lastly, in Listing 4-21 is the apache::virtual_host definition that allows us to create new virtual hosts on