diff options
author | David Schmitt <david@schmitt.edv-bus.at> | 2009-05-31 21:14:37 +0200 |
---|---|---|
committer | David Schmitt <david@schmitt.edv-bus.at> | 2009-05-31 21:14:37 +0200 |
commit | 53d0fde15feb30777a6929cada73d5f6e6ceb513 (patch) | |
tree | 1c81f431393991beabff6011a337dce2d0d76931 /manifests/defines/replace.pp | |
parent | 9a2c68367f8ac75ce52e315253d28f6710a80702 (diff) | |
download | puppet-common-53d0fde15feb30777a6929cada73d5f6e6ceb513.tar.gz puppet-common-53d0fde15feb30777a6929cada73d5f6e6ceb513.tar.bz2 |
Major cleanup of the common module
* improve documentation on all defines
* rename modules_dir to module_dir and modules_file to module_file
* create $module_dir_path to achieve DRY-ness
* silence the lsb_release stuff
* improve concatenated_file to use an intermediate file, improving reliability
and decoupling the updateing from notifying our peers.
* remove serveral functions that were moved to puppet proper:
- sha1 => sha1
- gsub,substitute,slash_escape => regsubst
Diffstat (limited to 'manifests/defines/replace.pp')
-rw-r--r-- | manifests/defines/replace.pp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/manifests/defines/replace.pp b/manifests/defines/replace.pp index c13325e..a7a59b8 100644 --- a/manifests/defines/replace.pp +++ b/manifests/defines/replace.pp @@ -2,6 +2,13 @@ # 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. +# # Usage: # # replace { description: @@ -20,8 +27,9 @@ # } define replace($file, $pattern, $replacement) { - $pattern_no_slashes = slash_escape($pattern) - $replacement_no_slashes = slash_escape($replacement) + $pattern_no_slashes = regsubst($pattern, '/', '\\/', 'G', 'U') + $replacement_no_slashes = regsubst($replacement, '/', '\\/', 'G', 'U') + 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}'", |