On Thursday, July 23, 2015 at 7:13:46 PM UTC+5:30, jcbollinger wrote:
>
>
>
> On Thursday, July 23, 2015 at 2:27:03 AM UTC-5, Ayyanar wrote:
>>
>> 1."       sed -i 's/\$\$HISTORY\$\$/puppet/'                     /etc/
>> system.com      "
>>
>>
>> I want to replace a word $$HISTORY$$ with puppet text into /etc/
>> system.com file.
>>
>>
>
> You have to take care to perform proper quoting/escaping for sed, possibly 
> to quote/escape the result for the shell (only if you are running the 
> command via the shell), and then to quote/escape *that* result for 
> Puppet.  From sed's perspective, the program you want to run is
>
> s/$$HISTORY$\$/puppet/
>
> (The '$' is special in a sed pattern only when it appears at the end of 
> the pattern, or, for GNU sed, at the end of a sub-expression.)
>
> It will save you some trouble to cut the shell out of it, so supposing you 
> are going to use a Puppet Exec resource to run sed, you should rely on the 
> 'posix' provider (the default where it is available), and avoid the 'shell' 
> provider.
>
> If you don't need Puppet to interpolate any variables into the command 
> string (as in your example) then it's not much harder than that:
>
> exec { 'Fill system.com':
>   command => '/bin/sed -i \'s/$$HISTORY$\\$/puppet/\' /etc/system.com'
> }
>
> Note that the backslash you want passed through to sed needs to be escaped 
> to Puppet.  Quoting the whole command string with single quotes prevents 
> Puppet from interpreting any of the dollar signs as introducing a variable 
> interpolation.  You might not need -- and even might not want -- the 
> internal single quotes around the sed program, but if you include them then 
> they must be escaped as shown.
>
> You can trick that out a bit, if you like.  Personally, I'd probably do 
> this:
>
> exec { 'Fill system.com':
>   command => '/bin/sed -i \'s/$$HISTORY$\\$/puppet/\' /etc/system.com',
>   onlyif => '/usr/bin/test -e /etc/system.com',
>   refresh => '/bin/true',
>   provider => 'posix'
> }
>
> Or in truth, if at all possible I would manage the whole file via Puppet.  
> A Puppet template might be helpful for that, but for the specific example 
> you provided it would be overkill (no need to use a template to sub a 
> constant string into a template at run time when you could just edit it 
> into the master's copy of the file in the first place).
>
>
> John
>

Thanks John It is works for me.

 

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/54872ec2-7ddb-4ba4-9ded-47a5f684941c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to