I naturally tried using backslash to escape the quotes since that is 
pretty much the standard in scripting, but that just resulted in the 
backslash getting embedded into the result:

    lineinfile: dest=/etc/mail/sendmail.mc state=present 
regexp='SMART_HOST' line="define(\`SMART_HOST\', \`{{smarthost}}\')dnl"
    generates:  define(\\`SMART_HOST\', \\`mailgw-sin.go2uti.com\')dnl

     When I researched this on the Internet, I found 
this:https://github.com/dotmaster/toYaml/issues/1  Essentially, the proper 
way to escape a quote is with another quote.  Except that isn't quite 
working either (example in my original post).
    What I found out minutes ago is that it appears to be related to the OS 
version.  When I use this:

    lineinfile: dest=/etc/mail/sendmail.mc state=present 
regexp='SMART_HOST' line="define(`SMART_HOST', `{{smarthost}}')dnl"

it works perfectly when the target server is OEL6.5 but with OEL5.5 as the 
target server it generates  define(\`SMART_HOST', 
\`mailgw-sin.go2uti.com')dnl.
    So something in OEL5.5 wants to escape the backtick during processing, 
but does not do that in OEL6.5.

    I tried using the replace module instead:

    replace: dest=/etc/mail/sendmail.mc regexp="^define.*SMART_HOST.*dnl$"  
replace="define(`SMART_HOST', `{{smarthost}}')dnl"

and that works perfectly on both flavors of OS.  I don't know why since the 
replace value of the replace module is identical to the line value of the 
lineinfile module.  There is a bug someplace in the chain when OEL5.5 is 
the target, but we don't build very many OEL5.5 servers anymore, so I don't 
think I am going to lose too much sleep over this.  What ever works, I 
guess.  
    -Mark




On Monday, November 17, 2014 12:45:49 PM UTC-8, Michael DeHaan wrote:
>
> A good trick with the lineinfile module is almost always to use the 
> template module if you can :)
>
> The problem here is if you start something with a quote, it assumes that 
> quote is not part of the string and then will end the quote.
>
> Thus you might find it easier to just escape quotes with \" or \' when 
> needed.
>
>
>
>
>
> On Sun, Nov 16, 2014 at 11:59 PM, <[email protected] <javascript:>> wrote:
>
>>
>>     I am using the lineinfile module to define the SMART_HOST value in a 
>> sendmail.mc file.  I have tried many variations of specifying the 
>> 'line=' value, but all generate almost but not quite correct results.
>>     For example: lineinfile: dest=/etc/mail/sendmail.mc state=present 
>> regexp='SMART_HOST' line="define(`SMART_HOST', `{{smarthost}}')dnl"
>>     generates:  define(\`SMART_HOST', \`gateway.here.com')dnl
>>
>>     Or: lineinfile: dest=/etc/mail/sendmail.mc state=present 
>> regexp='SMART_HOST' line='define(`SMART_HOST'', `{{smarthost}}'')dnl'  
>> (that is two single quotes)
>>     generates:  define(`SMART_HOST, `gateway.here.com)dnl
>>
>>     And: lineinfile: dest=/etc/mail/sendmail.mc state=present 
>> regexp='SMART_HOST' line="define(`SMART_HOST"'", `{{smarthost}}"'")dnl"  
>> (double quote, single, double)
>>     generates:  define(`SMART_HOST", `gateway.here.com")dnl
>>  
>>     And so on.  Everything I have tried either comes close or just 
>> totally fails.  The result I am looking for is:  define(`SMART_HOST', `
>> gateway.here.com')dnl
>>     Does anyone know the proper quoting and escaping required to achieve 
>> this through YAML?
>>     Thanks,
>>     -Mark
>>
>>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/c46c39da-31ee-4eee-a52e-b39cf79b0668%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/c46c39da-31ee-4eee-a52e-b39cf79b0668%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/32b660b7-75a7-4744-9aea-5e6e71f1f79e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to