Report abuse

#Example from http://reductivelabs.com/trac/puppet/wiki/Recipes/SimpleText

#We've loaded these into our /etc/puppet/manifests/functions.pp

#Having problems with this:

#Replace a perl regexp with a string:

define replace($file, $pattern, $replacement) {
   $pattern_no_slashes = slash_escape($pattern)
   $replacement_no_slashes = slash_escape($replacement)
 
   exec { "/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/ && ! /$replacement_no_slashes/ ; END { exit \$ret; }' '$file'",
   }

#My "\s" in the input pattern is being replaced with a single space. I need all white space represented including tabs.