Puppet Module Cheat Sheet

ADVERTISEMENT

Puppet Module Cheat Sheet
Modules are directories with a predictable structure.
Puppet can automatically load manifests, files, and plugins from modules in its modulepath.
Use
to see where Puppet expects to find modules on your system.
puppet --configprint modulepath
Example Module: /etc/puppetlabs/puppet/modules/apache
manifests
files
This directory holds the module's Puppet code.
Nodes can download any files in this directory from
Each .pp file should contain one and only one class
Puppet's built-in file server.
or defined type.
Use the
attribute to download file contents
source
Filenames and class/defined type names are related;
from the server.
see the examples below.
Use
URIs to specify which file to fetch.
puppet:///
Within a module, the special
variable
Files in this directory are served at
$module_name
always contains the module's name.
.
puppet:///modules/modulename/filename
apache/manifests/init.pp
apache/files/httpd.conf
To fetch this file:
class apache {
...
file {'/etc/apache2/httpd.conf':
}
ensure => file,
source => 'puppet:///modules/apache/httpd.conf',
Init.pp is special; it should contain a class (or define)
}
with the same name as the module.
apache/manifests/vhost.pp
apache/files/extra/ssl
Puppet's file server can navigate any subdirectories:
define apache::vhost ($port, $docroot) {
...
file {'/etc/apache2/httpd-ssl.conf':
}
ensure => file,
source => 'puppet:///modules/apache/extra/ssl',
Other classes (and defines) should be named
}
(without the .pp extension).
modulename::filename
apache/manifests/config/ssl.pp
templates
class apache::config::ssl {
...
This directory holds ERB templates.
}
Use the
function to create a string by
template
rendering a template.
Subdirectories add intermediate namespaces.
Use the
attribute to fill file contents with a
content
string.
Template files are referenced as
lib
.
modulename/filename.erb
This directory holds Ruby plugins, which can add features
apache/templates/vhost.erb
to Puppet and Facter.
To use this template:
apache/lib/puppet/type/apache_setting.rb
file {'/etc/apache2/sites-enabled/wordpress.conf':
A custom type.
ensure
=> file,
content => template('apache/vhost.erb'),
}
apache/lib/puppet/parser/functions/htpasswd.rb
A custom function.
apache/lib/facter/apache_confdir.rb
A custom fact.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go