aboutsummaryrefslogtreecommitdiff
path: root/manifests
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2011-02-14 12:11:35 -0200
committerSilvio Rhatto <rhatto@riseup.net>2011-02-14 12:11:35 -0200
commit0b03f41b32e8423bbbfa3c8a6b02dbf17c04f4c1 (patch)
treec5d7863c96377394b8559fbd5c7777fb32b6fda1 /manifests
parente0080adb1ca115ee98bf97c9cfb91fccbfeddaac (diff)
parenta81984c77ed1efb56e978d8b5050b6c3ec409d80 (diff)
downloadpuppet-common-0b03f41b32e8423bbbfa3c8a6b02dbf17c04f4c1.tar.gz
puppet-common-0b03f41b32e8423bbbfa3c8a6b02dbf17c04f4c1.tar.bz2
Merge branch 'master' of git://labs.riseup.net/shared-common
Conflicts: lib/puppet/parser/functions/gsub.rb lib/puppet/parser/functions/prefix_with.rb lib/puppet/parser/functions/slash_escape.rb lib/puppet/parser/functions/split.rb lib/puppet/parser/functions/substitute.rb manifests/classes/lsb_release.pp manifests/defines/concatenated_file.pp manifests/defines/config_file.pp manifests/defines/line.pp manifests/defines/module_dir.pp manifests/defines/module_file.pp manifests/defines/replace.pp manifests/init.pp
Diffstat (limited to 'manifests')
-rw-r--r--manifests/classes/lsb_release.pp49
-rw-r--r--manifests/defines/concatenated_file.pp148
-rw-r--r--manifests/defines/config_file.pp60
-rw-r--r--manifests/defines/line.pp32
-rw-r--r--manifests/defines/link.pp12
-rw-r--r--manifests/defines/module_dir.pp63
-rw-r--r--manifests/defines/module_file.pp51
-rw-r--r--manifests/defines/replace.pp29
-rw-r--r--manifests/init.pp20
-rw-r--r--manifests/moduledir.pp15
-rw-r--r--manifests/moduledir/common.pp3
-rw-r--r--manifests/moduledir/common/cf.pp4
12 files changed, 232 insertions, 254 deletions
diff --git a/manifests/classes/lsb_release.pp b/manifests/classes/lsb_release.pp
deleted file mode 100644
index c08b8c2..0000000
--- a/manifests/classes/lsb_release.pp
+++ /dev/null
@@ -1,49 +0,0 @@
-# common/manifests/classes/lsb_release.pp -- request the installation of
-# lsb_release to get to lsbdistcodename, which is used throughout the manifests
-#
-# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
-# See LICENSE for the full license granted to you.
-
-# Changelog:
-# 2007-08-26: micah <micah@riseup.net> reported, that lsb_release can report
-# nonsensical values for lsbdistcodename; assert_lsbdistcodename now
-# recognises "n/a" and acts accordingly
-
-# This lightweight class only asserts that $lsbdistcodename is set.
-# If the assertion fails, an error is printed on the server
-#
-# To fail individual resources on a missing lsbdistcodename, require
-# Exec[assert_lsbdistcodename] on the specific resource
-#
-# This is just one example of how you could avoid evaluation of parts of the
-# manifest, before a bootstrapping class has enabled all the necessary goodies.
-class assert_lsbdistcodename {
-
- case $lsbdistcodename {
- '': {
- err("Please install lsb_release or set facter_lsbdistcodename in the environment of $fqdn")
- exec { "false # assert_lsbdistcodename": alias => assert_lsbdistcodename, loglevel => err }
- }
- 'n/a': {
- case $operatingsystem {
- "Debian": {
- err("lsb_release was unable to report your distcodename; This seems to indicate a broken apt/sources.list on $fqdn")
- }
- default: {
- err("lsb_release was unable to report your distcodename; please set facter_lsbdistcodename in the environment of $fqdn")
- }
- }
- exec { "/bin/false # assert_lsbdistcodename": alias => assert_lsbdistcodename, loglevel => err }
- }
- default: {
- exec { "/bin/true # assert_lsbdistcodename": alias => assert_lsbdistcodename, loglevel => debug }
- exec { "/bin/true # require_lsbdistcodename": alias => require_lsbdistcodename, loglevel => debug }
- }
- }
-
-}
-
-# To fail the complete compilation on a missing $lsbdistcodename, include this class
-class require_lsbdistcodename inherits assert_lsbdistcodename {
- exec { "false # require_lsbdistcodename": require => Exec[require_lsbdistcodename], loglevel => err }
-}
diff --git a/manifests/defines/concatenated_file.pp b/manifests/defines/concatenated_file.pp
index b85456c..fc2c7a3 100644
--- a/manifests/defines/concatenated_file.pp
+++ b/manifests/defines/concatenated_file.pp
@@ -24,94 +24,102 @@ module_dir { "common/cf": }
#
# 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",
+# dir => "/etc/some.conf.d",
# }
define concatenated_file (
- # where the snippets are located
- $dir = '',
- # a file with content to prepend
- $header = '',
- # a file with content to append
- $footer = '',
- # default permissions for the target file
- $mode = 0644, $owner = root, $group = 0
- )
+ $ensure = 'present',
+ # where the snippets are located
+ $dir = '',
+ # a file with content to prepend
+ $header = '',
+ # a file with content to append
+ $footer = '',
+ # default permissions for the target file
+ $mode = 0644, $owner = root, $group = 0
+ )
{
+ include common::moduledir::common::cf
- $dir_real = $dir ? { '' => "${name}.d", default => $dir }
-
- $tmp_file_name = regsubst($dir_real, '/', '_', 'G')
- $tmp_file = "${module_dir_path}/${tmp_file_name}"
+ $dir_real = $dir ? { '' => "${name}.d", default => $dir }
- if defined(File[$dir_real]) {
- debug("${dir_real} already defined")
- } else {
- file {
- $dir_real:
- source => "puppet://$server/modules/common/empty",
- checksum => mtime,
- ignore => '.ignore',
- recurse => true, purge => true, force => true,
- mode => $mode, owner => $owner, group => $group,
- notify => Exec["concat_${name}"];
- }
- }
+ $tmp_file_name = regsubst($dir_real, '/', '_', 'G')
+ $tmp_file = "${common::moduledir::module_dir_path}/${tmp_file_name}"
- file {
- $tmp_file:
- ensure => present, checksum => md5,
- mode => $mode, owner => $owner, group => $group;
- # decouple the actual file from the generation process by using a
- # temporary file and puppet's source mechanism. This ensures that events
- # for notify/subscribe will only be generated when there is an actual
- # change.
- $name:
- ensure => present, checksum => md5,
- source => $tmp_file,
- mode => $mode, owner => $owner, group => $group,
- require => File[$tmp_file];
- }
+ if defined(File[$dir_real]) {
+ debug("${dir_real} already defined")
+ } else {
+ file {
+ $dir_real:
+ ensure => $ensure ? {
+ 'present' => directory,
+ default => $ensure
+ },
+ source => "puppet:///modules/common/empty",
+ checksum => mtime,
+ ignore => '.ignore',
+ recurse => true, purge => true, force => true,
+ mode => $mode, owner => $owner, group => $group,
+ notify => Exec["concat_${name}"];
+ }
+ }
- # if there is a header or footer file, add it
- $additional_cmd = $header ? {
- '' => $footer ? {
- '' => '',
- default => "| cat - '${footer}' "
- },
- default => $footer ? {
- '' => "| cat '${header}' - ",
- default => "| cat '${header}' - '${footer}' "
- }
- }
+ file {
+ $tmp_file:
+ ensure => $ensure, checksum => md5,
+ mode => $mode, owner => $owner, group => $group;
+ # decouple the actual file from the generation process by using a
+ # temporary file and puppet's source mechanism. This ensures that events
+ # for notify/subscribe will only be generated when there is an actual
+ # change.
+ $name:
+ ensure => $ensure, checksum => md5,
+ source => $tmp_file,
+ mode => $mode, owner => $owner, group => $group,
+ require => File[$tmp_file];
+ }
- # use >| to force clobbering the target file
- exec { "concat_${name}":
- command => "/usr/bin/find ${dir_real} -maxdepth 1 -type f ! -name '*puppettmp' -print0 | sort -z | xargs -0 cat ${additional_cmd} >| ${tmp_file}",
- subscribe => [ File[$dir_real] ],
- before => File[$tmp_file],
- alias => [ "concat_${dir_real}"],
- loglevel => info
- }
+ if $ensure == 'present' {
+ # if there is a header or footer file, add it
+ $additional_cmd = $header ? {
+ '' => $footer ? {
+ '' => '',
+ default => "| cat - '${footer}' "
+ },
+ default => $footer ? {
+ '' => "| cat '${header}' - ",
+ default => "| cat '${header}' - '${footer}' "
+ }
+ }
+ # use >| to force clobbering the target file
+ exec { "concat_${name}":
+ command => "/usr/bin/find ${dir_real} -maxdepth 1 -type f ! -name '*puppettmp' -print0 | sort -z | xargs -0 cat ${additional_cmd} >| ${tmp_file}",
+ subscribe => [ File[$dir_real] ],
+ before => File[$tmp_file],
+ alias => [ "concat_${dir_real}"],
+ loglevel => info
+ }
+ }
}
# Add a snippet called $name to the concatenated_file at $dir.
# The file can be referenced as File["cf_part_${name}"]
define concatenated_file_part (
- $dir, $content = '', $ensure = present,
- $mode = 0644, $owner = root, $group = 0
- )
+ $dir, $content = '', $ensure = present,
+ $mode = 0644, $owner = root, $group = 0
+ )
{
- file { "${dir}/${name}":
- ensure => $ensure, content => $content,
- mode => $mode, owner => $owner, group => $group,
- alias => "cf_part_${name}",
- notify => Exec["concat_${dir}"],
- }
+ file { "${dir}/${name}":
+ ensure => $ensure, content => $content,
+ mode => $mode, owner => $owner, group => $group,
+ alias => "cf_part_${name}",
+ notify => Exec["concat_${dir}"],
+ }
}
+
diff --git a/manifests/defines/config_file.pp b/manifests/defines/config_file.pp
index 781e9ec..375e25c 100644
--- a/manifests/defines/config_file.pp
+++ b/manifests/defines/config_file.pp
@@ -5,11 +5,11 @@
# 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:
@@ -24,35 +24,33 @@
# 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"];
-# }
-define config_file (
- $content = '',
- $source = '',
- $ensure = 'present')
-{
- file { $name:
- ensure => $ensure,
- # default permissions for config files
- mode => 0644, owner => root, group => 0,
- # really detect changes to this file
- checksum => md5,
- }
+# config_file { "/etc/apache2/sites-available/munin-stats":
+# content => template("apache/munin-stats"),
+# require => Package["apache2"],
+# notify => Exec["reload-apache2"]
+# }
+
+define config_file ($content = '', $source = '', $ensure = 'present') {
+ file { $name:
+ ensure => $ensure,
+ # keep old versions on the server
+ backup => puppet,
+ # default permissions for config files
+ mode => 0644, owner => root, group => 0,
+ # really detect changes to this file
+ checksum => md5,
+ }
+
+ case $source {
+ '': { }
+ default: { File[$name] { source => $source } }
+ }
- case $source {
- '': { }
- default: { File[$name] { source => $source } }
- }
+ case $content {
+ '': { }
+ default: { File[$name] { content => $content } }
+ }
- case $content {
- '': { }
- default: { File[$name] { content => $content } }
- }
-
}
diff --git a/manifests/defines/line.pp b/manifests/defines/line.pp
index 832382f..44c52a0 100644
--- a/manifests/defines/line.pp
+++ b/manifests/defines/line.pp
@@ -14,11 +14,10 @@
# is a more stable solution with less maintenance headaches afterwards.
#
# Usage:
-# line {
-# description:
-# file => "filename",
-# line => "content",
-# ensure => {absent,*present*}
+# line { description:
+# file => "filename",
+# line => "content",
+# ensure => {absent,*present*}
# }
#
# Example:
@@ -39,27 +38,16 @@
# http://reductivelabs.com/trac/puppet/wiki/Recipes/SimpleText
define line($file, $line, $ensure = 'present') {
case $ensure {
- default: { err ( "unknown ensure value ${ensure}" ) }
+ default : { err ( "unknown ensure value '${ensure}'" ) }
present: {
- exec { "/bin/echo '${line}' >> '${file}'":
- unless => "/bin/grep -qFx '${line}' '${file}'",
- require => File["${file}"],
+ exec { "echo '${line}' >> '${file}'":
+ unless => "grep -qFx '${line}' '${file}'"
}
}
absent: {
- exec { "/usr/bin/perl -ni -e 'print unless /^\\Q${line}\\E\$/' '${file}'":
- onlyif => "/bin/grep -qFx '${line}' '${file}'",
- }
- }
- uncomment: {
- exec { "/bin/sed -i -e'/${line}/s/^#\+//' '${file}'":
- onlyif => "/bin/grep '${line}' '${file}' | /bin/grep '^#' | /usr/bin/wc -l"
- }
- }
- comment: {
- exec { "/bin/sed -i -e'/${line}/s/^\(.\+\)$/#\1/' '${file}'":
- onlyif => "/usr/bin/test `/bin/grep '${line}' '${file}' | /bin/grep -v '^#' | /usr/bin/wc -l` -ne 0",
- require => File["${file}"],
+ $subst_line = regsubst($line,'(/|\.)','\\\1','G')
+ exec { "sed -i '/${subst_line}/d' '${file}'":
+ onlyif => "grep -qFx '${line}' '${file}'"
}
}
}
diff --git a/manifests/defines/link.pp b/manifests/defines/link.pp
new file mode 100644
index 0000000..e8e4a9f
--- /dev/null
+++ b/manifests/defines/link.pp
@@ -0,0 +1,12 @@
+# common/manifests/defines/link.pp -- create a link
+#
+# Copyleft (C) 2009 immerdaadmin <admin@immerda.ch>
+# See LICENSE for the full license granted to you.
+
+# Usage:
+# link { "/usr/bin/convert": target => "/usr/local/bin/convert" }
+# e.g. equivalent to bash# ln -s /usr/bin/convert /usr/local/bin/convert
+
+define link($target = absent) {
+ file{$name: ensure => $target; }
+}
diff --git a/manifests/defines/module_dir.pp b/manifests/defines/module_dir.pp
index def5c94..613cc49 100644
--- a/manifests/defines/module_dir.pp
+++ b/manifests/defines/module_dir.pp
@@ -1,42 +1,41 @@
-# common/manifests/defines/module_dir.pp -- create a default directory
+# common/manifests/defines/modules_dir.pp -- create a default directory
# for storing module specific information
#
# 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 }
+}
diff --git a/manifests/defines/module_file.pp b/manifests/defines/module_file.pp
index 9074589..43b3c48 100644
--- a/manifests/defines/module_file.pp
+++ b/manifests/defines/module_file.pp
@@ -1,24 +1,45 @@
-# common/manifests/defines/module_file.pp -- use an already defined module_dir
-# to store module specific files
+# common/manifests/defines/modules_file.pp -- use a modules_dir to store module
+# specific files
#
# 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
+ )
+{
+ 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
+ )
{
- file {
- "${module_dir_path}/${name}":
- source => $source,
- mode => $mode, owner => $owner, group => $group;
- }
+ module_file { $name:
+ source => $source,
+ ensure => $ensure,
+ alias => $alias,
+ mode => $mode, owner => $owner, group => $group
+ }
}
diff --git a/manifests/defines/replace.pp b/manifests/defines/replace.pp
index c9a98bd..f7da3b4 100644
--- a/manifests/defines/replace.pp
+++ b/manifests/defines/replace.pp
@@ -14,7 +14,7 @@
#
# Usage:
#
-# replace { description:
+# replace { description:
# file => "filename",
# pattern => "regexp",
# replacement => "replacement"
@@ -23,19 +23,18 @@
# 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"
-# }
-define replace($file, $pattern, $replacement) {
- $pattern_no_slashes = regsubst($pattern, '/', '\\/', 'G', 'U')
- $replacement_no_slashes = regsubst($replacement, '/', '\\/', 'G', 'U')
+# replace { set_munin_node_port:
+# file => "/etc/munin/munin-node.conf",
+# pattern => "^port (?!$port)[0-9]*",
+# replacement => "port $port"
+# }
- exec { "replace_${pattern}_${file}":
- command => "/usr/bin/perl -pi -e 's/${pattern_no_slashes}/${replacement_no_slashes}/' '${file}'",
- onlyif => "/usr/bin/perl -ne 'BEGIN { \$ret = 1; } \$ret = 0 if /${pattern_no_slashes}/ && ! /\\Q${replacement_no_slashes}\\E/; END { exit \$ret; }' '${file}'",
- alias => "exec_$name",
- }
+define replace($file, $pattern, $replacement) {
+ $pattern_no_slashes = slash_escape($pattern)
+ $replacement_no_slashes = slash_escape($replacement)
+ exec { "replace_${pattern}_${file}":
+ command => "/usr/bin/perl -pi -e 's/${pattern_no_slashes}/${replacement_no_slashes}/' '${file}'",
+ onlyif => "/usr/bin/perl -ne 'BEGIN { \$ret = 1; } \$ret = 0 if /${pattern_no_slashes}/ && ! /\\Q${replacement_no_slashes}\\E/; END { exit \$ret; }' '${file}'",
+ alias => "exec_$name",
+ }
}
diff --git a/manifests/init.pp b/manifests/init.pp
index f767030..3770897 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -3,23 +3,3 @@
# 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 } }
-
diff --git a/manifests/moduledir.pp b/manifests/moduledir.pp
new file mode 100644
index 0000000..df83e60
--- /dev/null
+++ b/manifests/moduledir.pp
@@ -0,0 +1,15 @@
+class common::moduledir {
+ # Use this variable to reference the base path. Thus you are safe from any
+ # changes.
+ $module_dir_path = '/var/lib/puppet/modules'
+
+ # Module programmers can use /var/lib/puppet/modules/$modulename to save
+ # module-local data, e.g. for constructing config files
+ file{$module_dir_path:
+ ensure => directory,
+ source => "puppet:///modules/common/modules/",
+ ignore => '.ignore',
+ recurse => true, purge => true, force => true,
+ mode => 0755, owner => root, group => 0;
+ }
+}
diff --git a/manifests/moduledir/common.pp b/manifests/moduledir/common.pp
new file mode 100644
index 0000000..c615f84
--- /dev/null
+++ b/manifests/moduledir/common.pp
@@ -0,0 +1,3 @@
+class common::moduledir::common{
+ module_dir{'common': }
+}
diff --git a/manifests/moduledir/common/cf.pp b/manifests/moduledir/common/cf.pp
new file mode 100644
index 0000000..b3c089b
--- /dev/null
+++ b/manifests/moduledir/common/cf.pp
@@ -0,0 +1,4 @@
+class common::moduledir::common::cf {
+ include ::common::moduledir::common
+ module_dir{'common/cf': }
+}