another geek another geek - 1 year ago 509
YAML Question

Ansible lineinfile escape special characters

I'm trying to replace a line in a remote file using


It's a
file, containing:

'cache' => true,

I tried a lot of different solutions but no one worked. I feel I'm just too close but I can't do it. Could you please help me?
This is what I've done:

lineinfile: "dest=/home/ubuntu/www/2.5.0/app/config/preprod/app.php regexp=^\'cache\'=> line=\'cache\' => {{ var }}"

is either true or false, is a parameter set via the command line. The output shows me a line is added. but this not what I want. Thank you in advance.

Answer Source

Avoid using param=value in complex cases, use dict style instead, it's a lot easier to read:

 - lineinfile:
     dest: "/home/ubuntu/www/2.5.0/app/config/preprod/app.php"
     regexp: "^'cache' =>"
     line: "'cache' => {{ var | string | lower }},"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download