diff options
author | root <root@puppetmaster.black.co.at> | 2007-09-11 10:29:38 +0200 |
---|---|---|
committer | root <root@puppetmaster.black.co.at> | 2007-09-11 10:29:38 +0200 |
commit | 67ea4bb276d3103330b1f9e1668bd0db749f4313 (patch) | |
tree | c3b6d40820a87fc8ee3dc8402000eb919cd197cb /manifests/defines | |
parent | a3e3bafd50056a204d16f058543a93ca3dec4e40 (diff) | |
download | puppet-common-67ea4bb276d3103330b1f9e1668bd0db749f4313.tar.gz puppet-common-67ea4bb276d3103330b1f9e1668bd0db749f4313.tar.bz2 |
moved "replace" define to module
Diffstat (limited to 'manifests/defines')
-rw-r--r-- | manifests/defines/replace.pp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/manifests/defines/replace.pp b/manifests/defines/replace.pp new file mode 100644 index 0000000..ae4498e --- /dev/null +++ b/manifests/defines/replace.pp @@ -0,0 +1,25 @@ +# 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. + +# Usage: +# +# # replace the current port in /etc/munin/munin-node.conf +# # with a new, 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/; END { exit \$ret; }' '$file'", + alias => "exec_$name", + } +} + + + |