another geek another geek - 2 months ago 55x
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.


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 }},"