Actually your example works like this:
The contents of the .htaccess file:
Uncomplicated game:
- name: Make sure PHP Errors are turned on lineinfile: dest: "{{ www_path }}/.htaccess" line: "php_flag display_errors on"
The results of a game with an indecisive play with this game:
$ cat .htaccess
If the file starts with a commented line, you will see that the second line is uncommented. To fix this, use a regex that matches the existing string and replaces it:
- lineinfile: dest: /Users/bwhaley/tmp/file regexp: '^#php_flag display_errors' line: 'php_flag display_errors' backrefs: yes
Please note that with backrefs: yes , if the line you want to uncomment is no longer present and is not commented on, the game will not change at all.
source share