aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README17
-rw-r--r--lib/puppet/parser/functions/basename.rb12
-rw-r--r--lib/puppet/parser/functions/dirname.rb10
-rw-r--r--lib/puppet/parser/functions/re_escape.rb2
-rw-r--r--lib/puppet/parser/functions/split.rb12
-rw-r--r--manifests/defines/append_if_no_such_line.pp14
-rw-r--r--manifests/defines/config_file.pp2
-rw-r--r--manifests/defines/line.pp43
-rw-r--r--manifests/defines/module_dir.pp9
-rw-r--r--manifests/defines/module_file.pp2
-rw-r--r--manifests/defines/replace.pp10
-rw-r--r--manifests/init.pp1
12 files changed, 103 insertions, 31 deletions
diff --git a/README b/README
index d34d11f..45b0106 100644
--- a/README
+++ b/README
@@ -1,17 +1,22 @@
-The common module installs various functions that are required by other modules. This
-module should be installed before any of the other module.
+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:
-1. Your modules directory will need all the files included in this repository placed
- under a directory called "common"
+1. Your modules directory will need all the files included in this
+ repository placed under a directory called "common"
2. Add the following line to manifests/site.pp:
- import "modules.pp"
+ import "modules.pp"
3. Add the following line to manifests/modules.pp:
- import "common"
+ import "common"
+
+
+Author:: David Schmitt (mailto:david@dasz.at)
+Copyright:: Copyright (c) 2007-2009 dasz.at OG
+License:: 3-clause BSD
diff --git a/lib/puppet/parser/functions/basename.rb b/lib/puppet/parser/functions/basename.rb
index 226d6e5..dc72537 100644
--- a/lib/puppet/parser/functions/basename.rb
+++ b/lib/puppet/parser/functions/basename.rb
@@ -1,9 +1,15 @@
-# basename(string) : string
-# basename(string[]) : string[]
+# This function has two modes of operation:
+#
+# basename(string) : string
#
# Returns the last component of the filename given as argument, which must be
-# formed using forward slashes (``/..) regardless of the separator used on the
+# formed using forward slashes ("/") regardless of the separator used on the
# local file system.
+#
+# basename(string[]) : string[]
+#
+# Returns an array of strings with the basename of each item from the argument.
+#
module Puppet::Parser::Functions
newfunction(:basename, :type => :rvalue) do |args|
if args[0].is_a?(Array)
diff --git a/lib/puppet/parser/functions/dirname.rb b/lib/puppet/parser/functions/dirname.rb
index 44b4a00..ea0d50b 100644
--- a/lib/puppet/parser/functions/dirname.rb
+++ b/lib/puppet/parser/functions/dirname.rb
@@ -1,9 +1,15 @@
-# dirname(string) : string
-# dirname(string[]) : string[]
+# This function has two modes of operation:
+#
+# dirname(string) : string
#
# Returns all components of the filename given as argument except the last
# one. The filename must be formed using forward slashes (``/..) regardless of
# the separator used on the local file system.
+#
+# dirname(string[]) : string[]
+#
+# Returns an array of strings with the basename of each item from the argument.
+#
module Puppet::Parser::Functions
newfunction(:dirname, :type => :rvalue) do |args|
if args[0].is_a?(Array)
diff --git a/lib/puppet/parser/functions/re_escape.rb b/lib/puppet/parser/functions/re_escape.rb
index 6e5904b..7bee90a 100644
--- a/lib/puppet/parser/functions/re_escape.rb
+++ b/lib/puppet/parser/functions/re_escape.rb
@@ -1,4 +1,4 @@
-# apply regexp escaping to a string
+# apply ruby regexp escaping to a string
module Puppet::Parser::Functions
newfunction(:re_escape, :type => :rvalue) do |args|
Regexp.escape(args[0])
diff --git a/lib/puppet/parser/functions/split.rb b/lib/puppet/parser/functions/split.rb
index 5237c92..bffecc1 100644
--- a/lib/puppet/parser/functions/split.rb
+++ b/lib/puppet/parser/functions/split.rb
@@ -1,9 +1,15 @@
-# split($string, $delimiter) : $string
-# split($string[], $delimiter) : $string[][]
+# This function has two modes of operation:
#
-# Split the first argument(s) on every $delimiter. $delimiter is interpreted as
+# split($string, $delimiter) : $string
+#
+# Split the first argument on every $delimiter. $delimiter is interpreted as
# Ruby regular expression.
#
+# split($string[], $delimiter) : $string[][]
+#
+# Returns an array of split results with the result of applying split to each
+# item from the first argument.
+#
# For long-term portability it is recommended to refrain from using Ruby's
# extended RE features.
module Puppet::Parser::Functions
diff --git a/manifests/defines/append_if_no_such_line.pp b/manifests/defines/append_if_no_such_line.pp
new file mode 100644
index 0000000..6ccf9f9
--- /dev/null
+++ b/manifests/defines/append_if_no_such_line.pp
@@ -0,0 +1,14 @@
+#
+# This define is only for "CFEngine compatability". It is only a light
+# wrapper around the "line" define, which is equally dangerous, but at
+# least named according to a proper resource model.
+#
+define append_if_no_such_line($file, $line) {
+ line {
+ $name:
+ ensure => present,
+ file => $file,
+ line => $line;
+ }
+}
+
diff --git a/manifests/defines/config_file.pp b/manifests/defines/config_file.pp
index e580715..d624c10 100644
--- a/manifests/defines/config_file.pp
+++ b/manifests/defines/config_file.pp
@@ -2,6 +2,8 @@
# 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",
diff --git a/manifests/defines/line.pp b/manifests/defines/line.pp
index 7ca3191..ccfa357 100644
--- a/manifests/defines/line.pp
+++ b/manifests/defines/line.pp
@@ -2,27 +2,38 @@
# 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
#
+# 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}'" ) }
diff --git a/manifests/defines/module_dir.pp b/manifests/defines/module_dir.pp
index 613cc49..227fe71 100644
--- a/manifests/defines/module_dir.pp
+++ b/manifests/defines/module_dir.pp
@@ -4,6 +4,15 @@
# 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:
# include common::moduledir
# module_dir { ["common", "common/dir1", "common/dir2" ]: }
diff --git a/manifests/defines/module_file.pp b/manifests/defines/module_file.pp
index 43b3c48..70e5cbf 100644
--- a/manifests/defines/module_file.pp
+++ b/manifests/defines/module_file.pp
@@ -4,6 +4,8 @@
# 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:
# modules_file { "module/file":
# source => "puppet:///...",
diff --git a/manifests/defines/replace.pp b/manifests/defines/replace.pp
index 7dabe59..f7da3b4 100644
--- a/manifests/defines/replace.pp
+++ b/manifests/defines/replace.pp
@@ -2,6 +2,16 @@
# 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:
diff --git a/manifests/init.pp b/manifests/init.pp
index 3770897..3a9faf5 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -3,3 +3,4 @@
# See LICENSE for the full license granted to you.
import "defines/*.pp"
+