How do you ensure a specific line exists in a file and is uncommented with ansible's `lineinfile'
The line I want uncommented (in .htaccess
):
#php_flag display_errors on
I have used the following:
- name: Make sure PHP Errors are turned on
lineinfile: dest={{ www_path }}/.htaccess line="php_flag display_errors on"
Actually your example works as is:
Contents of the
.htaccess
file:The ansible play:
Results of ansible-playbook with this play:
If the file starts with the line commented you'll see a second line uncommented. To correct this, use a regexp that will match the existing line and replace it:
Note though that with
backrefs: yes
if the line you want uncommented is not already present and commented, the play will make no change at all.