The common module installs various functions that are required by other modules. This module should be installed before any of the other module.
To use this module, follow these directions:
import "modules.pp"
import "common"
| Author: | David Schmitt (david@dasz.at) |
| Copyright: | Copyright (c) 2007-2009 dasz.at OG |
| License: | 3-clause BSD |
| module_dir_path | = | /var/lib/puppet/modules | Use this variable to reference the base path. Thus you are safe from any changes. |
This resource collects file snippets from a directory ($dir) and concatenates them in lexical order of their names into a new file ($name). This can be used to collect information from disparate sources, when the target file format doesn‘t allow includes.
concatenated_file_part can be used to easily configure content for this.
If no $dir is specified, the target name with ’.d’ appended will be used.
The $dir is purged by puppet and will only contain explicitely configured files. This can be overridden by defining the directory before the concatenated_file.
Depend on File[$name] to change if and only if its contents change. Notify Exec["concat_${name}"] if you want to force an update.
Usage:
concatenated_file { "/etc/some.conf":
dir => "/etc/some.conf.d",
}
where the snippets are located a file with content to prepend a file with content to append default permissions for the target file
Add a snippet called $name to the concatenated_file at $dir. The file can be referenced as File["cf_part_${name}"]
A simple wrapper to give all configuration files common defaults.
Usage:
config_file { filename:
content => "....\n",
}
Examples:
To create the file /etc/vservers/${vs_name}/context with specific content:
config_file {
"/etc/vservers/${vs_name}/context":
content => "${context}\n",
notify => Exec["vs_restart_${vs_name}"],
require => Exec["vs_create_${vs_name}"];
}
To create the file /etc/apache2/sites-available/munin-stats with the content pulled from a template:
config_file {
"/etc/apache2/sites-available/munin-stats":
content => template("apache/munin-stats"),
require => Package["apache2"],
notify => Exec["reload-apache2"];
}
Ensures that a specific line is present or absent in a file. This can be very brittle, since even small changes can throw this off.
If the line is not present yet, it will be appended to the file.
The name of the define is not used. Just keep it (globally) unique and descriptive.
Use this only for very trivial stuff. Usually replacing the whole file is a more stable solution with less maintenance headaches afterwards.
Usage:
line {
description:
file => "filename",
line => "content",
ensure => {absent,*present*}
}
Example: The following ensures that the line "allow ^$munin_host$" exists in /etc/munin/munin-node.conf, and if there are any changes notify the service for a restart
line {
allow_munin_host:
file => "/etc/munin/munin-node.conf",
line => "allow ^$munin_host$",
ensure => present,
notify => Service[munin-node],
require => Package[munin-node];
}
A module_dir is a storage place for all the stuff a module might want to store. According to the FHS, this should go to /var/lib. Since this is a part of puppet, the full path is /var/lib/puppet/modules/${name}. Every module should # prefix its module_dirs with its name.
By default, the module_dir is loaded from "puppet:///${name}/module_dir". If that doesn‘t exist an empty directory is taken as source. The directory is purged so that modules do not have to worry about removing cruft.
Usage:
module_dir { ["common", "common/dir1", "common/dir2" ]: }
Put a file into module-local storage.
Usage:
module_file {
"module/file":
source => "puppet://..",
}
A hack to replace all ocurrances of a regular expression in a file with a specified string. Sometimes it can be less effort to replace only a single value in a huge config file instead of creating a template out of it. Still, creating a template is often better than this hack.
This define uses perl regular expressions.
Usage:
replace { description:
file => "filename",
pattern => "regexp",
replacement => "replacement"
Example: To replace the current port in /etc/munin/munin-node.conf with a new port, but only disturbing the file when needed:
replace {
set_munin_node_port:
file => "/etc/munin/munin-node.conf",
pattern => "^port (?!$port)[0-9]*",
replacement => "port $port"
}