diff options
author | mh <mh@immerda.ch> | 2010-01-09 14:23:03 +0100 |
---|---|---|
committer | Micah Anderson <micah@riseup.net> | 2010-09-02 18:14:15 -0400 |
commit | b4ce2e8769aaee3e5c65f059a7056d956c6c3842 (patch) | |
tree | 48040ec6fd0badf3a6516f4ac77816a9aa89714f /manifests | |
parent | 75f88ffda0e3f2128ed4108d3ed0035c48f00c5b (diff) | |
download | puppet-common-b4ce2e8769aaee3e5c65f059a7056d956c6c3842.tar.gz puppet-common-b4ce2e8769aaee3e5c65f059a7056d956c6c3842.tar.bz2 |
make the removal of line safer
Diffstat (limited to 'manifests')
-rw-r--r-- | manifests/defines/line.pp | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/manifests/defines/line.pp b/manifests/defines/line.pp index c055f5b..e5b7fd5 100644 --- a/manifests/defines/line.pp +++ b/manifests/defines/line.pp @@ -4,9 +4,9 @@ # Usage: # line { description: -# file => "filename", -# line => "content", -# ensure => {absent,*present*} +# file => "filename", +# line => "content", +# ensure => {absent,*present*} # } # # Example: @@ -24,19 +24,20 @@ # # define line($file, $line, $ensure = 'present') { - case $ensure { - default : { err ( "unknown ensure value '${ensure}'" ) } - present: { - exec { "echo '${line}' >> '${file}'": - unless => "grep -qFx '${line}' '${file}'" - } - } - absent: { - exec { "perl -ni -e 'print if \$_ ne \"${line}\n\";' '${file}'": - onlyif => "grep -qFx '${line}' '${file}'" - } - } - } + case $ensure { + default : { err ( "unknown ensure value '${ensure}'" ) } + present: { + exec { "echo '${line}' >> '${file}'": + unless => "grep -qFx '${line}' '${file}'" + } + } + absent: { + $subst_line = regsubst($line,'(/|\.)','\\\1','G') + exec { "/bin/sed -i '/${subst_line}/d' '${file}'": + onlyif => "/bin/grep -qFx '${line}' '${file}'" + } + } + } } |