aboutsummaryrefslogtreecommitdiff
path: root/manifests/defines/replace.pp
diff options
context:
space:
mode:
authormh <mh@immerda.ch>2013-01-03 16:49:04 +0100
committermh <mh@immerda.ch>2013-01-03 16:49:04 +0100
commit47c385f4794fae0257dd3ab85b637eca93ee38ec (patch)
tree57a9f8bdd0ad2a492b8a5566173620986d67edef /manifests/defines/replace.pp
parent50a1943175bd203116d100eb5cf4f01f2fc6ded1 (diff)
downloadpuppet-common-47c385f4794fae0257dd3ab85b637eca93ee38ec.tar.gz
puppet-common-47c385f4794fae0257dd3ab85b637eca93ee38ec.tar.bz2
cleanup module to work better on newer puppet versions
Diffstat (limited to 'manifests/defines/replace.pp')
-rw-r--r--manifests/defines/replace.pp40
1 files changed, 0 insertions, 40 deletions
diff --git a/manifests/defines/replace.pp b/manifests/defines/replace.pp
deleted file mode 100644
index dd8db4d..0000000
--- a/manifests/defines/replace.pp
+++ /dev/null
@@ -1,40 +0,0 @@
-# common/manifests/defines/replace.pp -- replace a pattern in a file with a string
-# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
-# See LICENSE for the full license granted to you.
-
-# A hack to replace all occurrences 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:
-# 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"
-# }
-
-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",
- }
-}