diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2009-07-29 16:48:09 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2009-07-29 16:48:09 -0300 |
commit | 485929e529e1e662249344faeedb643d2e7b9de8 (patch) | |
tree | 17ea5584634aaabeb8642de33120347d7eac1233 /manifests/defines | |
parent | 9e6cb5d208770c22708cf1960af1362cd4fdf323 (diff) | |
download | puppet-common-485929e529e1e662249344faeedb643d2e7b9de8.tar.gz puppet-common-485929e529e1e662249344faeedb643d2e7b9de8.tar.bz2 |
Trying to fix line defintion
Diffstat (limited to 'manifests/defines')
-rw-r--r-- | manifests/defines/line.pp | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/manifests/defines/line.pp b/manifests/defines/line.pp index be5ec31..534fd7c 100644 --- a/manifests/defines/line.pp +++ b/manifests/defines/line.pp @@ -34,24 +34,33 @@ # notify => Service[munin-node], # require => Package[munin-node]; # } -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}'" - } - } - } +# +# Code with fixes gathered at +# http://reductivelabs.com/trac/puppet/wiki/Recipes/SimpleText +define line($file, $line, $ensure = 'present') { + case $ensure { + default: { err ( "unknown ensure value ${ensure}" ) } + present: { + exec { "/bin/echo '${line}' >> '${file}'": + unless => "/bin/grep -qFx '${line}' '${file}'", + require => File["${file}"], + } + } + absent: { + exec { "/usr/bin/perl -ni -e 'print unless /^\\Q${line}\\E\$/' '${file}'": + onlyif => "/bin/grep -qFx '${line}' '${file}'", + } + } + uncomment: { + exec { "/bin/sed -i -e'/${line}/s/^#\+//' '${file}'": + onlyif => "/bin/grep '${line}' '${file}' | /bin/grep '^#' | /usr/bin/wc -l" + } + } + comment: { + exec { "/bin/sed -i -e'/${line}/s/^\(.\+\)$/#\1/' '${file}'": + onlyif => "/usr/bin/test `/bin/grep '${line}' '${file}' | /bin/grep -v '^#' | /usr/bin/wc -l` -ne 0", + require => File["${file}"], + } + } + } } - - |