# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
- #
+# A simple wrapper to give all configuration files common defaults.
++#
# Usage:
- # config_file { filename:
- # content => "....\n",
- # }
+ # config_file { filename:
+ # content => "....\n",
+ # }
#
- # Examples:
+ # Examples:
#
# To create the file /etc/vservers/${vs_name}/context with specific
# content:
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
-# Usage:
-# line { description:
-# file => "filename",
-# line => "content",
-# ensure => {absent,*present*}
-# }
+# 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.
#
-# 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
+# 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.
#
-# line { allow_munin_host:
-# file => "/etc/munin/munin-node.conf",
-# line => "allow ^$munin_host$",
-# ensure => present,
-# notify => Service[munin-node],
-# require => Package[munin-node],
+# 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
#
- define line(
- $file,
- $line,
- $ensure = 'present'
- ) {
- case $ensure {
- default : { err ( "unknown ensure value '${ensure}'" ) }
- present: {
- exec { "echo '${line}' >> '${file}'":
- unless => "grep -qFx '${line}' '${file}'"
- }
- }
- absent: {
- exec { "perl -ni -e 'print if \$_ ne \"${line}\n\";' '${file}'":
- onlyif => "grep -qFx '${line}' '${file}'"
- }
- }
- }
+# line {
+# allow_munin_host:
+# file => "/etc/munin/munin-node.conf",
+# line => "allow ^$munin_host$",
+# ensure => present,
+# notify => Service[munin-node],
+# require => Package[munin-node];
+# }
+ define line($file, $line, $ensure = 'present') {
+ case $ensure {
+ default : { err ( "unknown ensure value '${ensure}'" ) }
+ present: {
+ exec { "echo '${line}' >> '${file}'":
+ unless => "grep -qFx '${line}' '${file}'"
+ }
+ }
+ absent: {
+ $subst_line = regsubst($line,'(/|\.)','\\\1','G')
+ exec { "sed -i '/${subst_line}/d' '${file}'":
+ onlyif => "grep -qFx '${line}' '${file}'"
+ }
+ }
+ }
}
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
+# 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" ]: }
+ # include common::moduledir
+ # module_dir { ["common", "common/dir1", "common/dir2" ]: }
+ #
+ # You may refer to a file in module_dir by using :
+ # file { "${common::moduledir::module_dir_path}/somedir/somefile": }
+
define module_dir (
- $mode = 0644,
- $owner = root,
- $group = 0
- )
+ $mode = 0644, $owner = root, $group = 0
+ )
{
- $dir = "${module_dir_path}/${name}"
- if defined(File[$dir]) {
- debug("${dir} already defined")
- } else {
- file {
- $dir:
- source => [ "puppet://$server/modules/${name}/module_dir", "puppet://$server/modules/common/empty"],
- checksum => mtime,
- # ignore the placeholder
- ignore => '\.ignore',
- recurse => true, purge => true, force => true,
- mode => $mode, owner => $owner, group => $group;
- }
- }
+ include common::moduledir
+ $dir = "${common::moduledir::module_dir_path}/${name}"
+ if defined(File[$dir]) {
+ debug("${dir} already defined")
+ } else {
+ file {
+ $dir:
+ source => [ "puppet:///modules/${name}/modules_dir", "puppet:///modules/common/empty"],
+ checksum => mtime,
+ # ignore the placeholder
+ ignore => '.ignore',
+ recurse => true, purge => true, force => true,
+ mode => $mode, owner => $owner, group => $group;
+ }
+ }
}
- # Use this variable to reference the base path. Thus you are safe from any
- # changes.
- $module_dir_path = '/var/lib/puppet/modules'
+ # alias for compatibility
+ define modules_dir (
+ $mode = 0644, $owner = root, $group = 0
+ )
+ {
+ module_dir { $name: mode => $mode, owner => $owner, group => $group }
+ }
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
+# Put a file into module-local storage.
+#
# Usage:
- # module_file {
- # "module/file":
- # source => "puppet://..",
+ # modules_file { "module/file":
+ # source => "puppet:///...",
+ # mode => 644, # default
+ # owner => root, # default
+ # group => 0, # default
# }
define module_file (
- $source,
- $mode = 0644, $owner = root, $group = 0
- )
+ $source,
+ $ensure = present,
+ $alias = undef,
+ $mode = 0644, $owner = root, $group = 0
+ )
{
- file {
- "${module_dir_path}/${name}":
- source => $source,
- mode => $mode, owner => $owner, group => $group;
- }
+ include common::moduledir
+ file {
+ "${common::moduledir::module_dir_path}/${name}":
+ source => $source,
+ ensure => $ensure,
+ alias => $alias,
+ mode => $mode, owner => $owner, group => $group;
+ }
+ }
+
+ # alias for compatibility
+ define modules_file (
+ $source,
+ $ensure = present,
+ $alias = undef,
+ $mode = 0644, $owner = root, $group = 0
+ )
+ {
+ module_file { $name:
+ source => $source,
+ ensure => $ensure,
+ alias => $alias,
+ mode => $mode, owner => $owner, group => $group
+ }
}
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
+# 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.
+#
+# Use this only for very trivial stuff. Usually replacing the whole file is a
+# more stable solution with less maintenance headaches afterwards.
+#
# Usage:
#
- # replace { description:
+ # replace { description:
# file => "filename",
# pattern => "regexp",
# replacement => "replacement"
# See LICENSE for the full license granted to you.
import "defines/*.pp"
- import "classes/*.pp"
-
- module_dir { [ 'common' ]: }
-
- file {
- # Module programmers can use /var/lib/puppet/modules/$modulename to save
- # module-local data, e.g. for constructing config files. See module_dir
- # for details
- "/var/lib/puppet/modules":
- ensure => directory,
- source => "puppet://$server/modules/common/modules",
- ignore => ".ignore",
- recurse => true, purge => true, force => true,
- mode => 0755, owner => root, group => 0;
- }
-
- # common packages
- class pkg::openssl { package { openssl: ensure => installed } }
- class pkg::rsync { package { rsync: ensure => installed } }
+