Puppet: escape "/" in sed-command

I did a simple find/replace with sed in my Puppet exec-block, but ran into a problem with escaping the /-character. You can't escape characters with the backslash escape method in Puppet. My original piece:

    command => "sed -i 's/osa_ssl_cert =/osa_ssl_cert = \/usr\/share\/rhn\/RHN-ORG-TRUSTED-SSL-CERT/g' /etc/sysconfig/rhn/osad.conf"

As you can see with puppet syntax validator (puppet parser validate [file.pp]), Puppet does not recognize the backslash escape method:

$ puppet parser validate osad.pp /etc/puppet/modules/spacewalk/manifests/osad.pp
Warning: Unrecognised escape sequence '\/' in file /etc/puppet/modules/spacewalk/manifests/osad.pp at line 23

So i changed the sed command in the exec block to use | instead of / where i separate the sed-command's find and replace parts:

    command => "sed -i 's|osa_ssl_cert =|osa_ssl_cert = /usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT|g' /etc/sysconfig/rhn/osad.conf"

This seems to solve the problem.

comments powered by Disqus