aboutsummaryrefslogtreecommitdiff
path: root/manifests/defines/replace.pp
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/defines/replace.pp
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/defines/replace.pp')
-rw-r--r--manifests/defines/replace.pp29
1 files changed, 14 insertions, 15 deletions
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",
+ }
}