Using modules
One of the most important things you can do to make your Puppet manifests clearer and more maintainable is to organize them into modules.
A module is simply a way of grouping related things: for example, a webserver
module might include everything necessary for a machine to be a web server: Apache configuration files, virtual host templates, and the Puppet code necessary to deploy these.
Separating things into modules makes it easier to re-use and share code; it's also the most logical way to organize your manifests. In this example we'll create a module to manage memcached
, a memory caching system commonly used with web applications.
How to do it…
Here are the steps to create an example module.
Create the following new directories in your Puppet repo:
ubuntu@cookbook:~/puppet$ mkdir modules/memcached ubuntu@cookbook:~/puppet$ mkdir modules/memcached/manifests ubuntu@cookbook:~/puppet$ mkdir modules/memcached/files
Create the file
modules/memcached/manifests/init.pp
with the following...