lineinfile Questions

I’m pretty new to Ansible, but I’m diving in.

My problem is that I need a playbook entry that will set a config value to a certain value if it’s different and return “ok” instead of “changed” if it’s already set.

This example always reports “changed”:

  • name: set apache ExtendedStatus
    lineinfile: dest=/etc/httpd/conf/httpd.conf regexp=^.ExtendedStatus.Off line=“ExtendedStatus On”
    register: apache_server_extended_status

I’ve tried using backrefs, but it seems to duplicate the line at the end under certain circumstances.

This example always seem to duplicate the line at the bottom of the file:

  • name: configure webmin listening port
    lineinfile: dest=/etc/webmin/miniserv.conf regexp=^listen=(?!10000).+ line=listen=10000 backrefs=yes
    register: webmin_listening_port

Can someone give me some advice on what I’m doing wrong?

Doug

I think your regexp might not be matching the line (because of "^.",
requiring a character before ExtendedStatus).

Please try this:

- name: set apache ExtendedStatus
  lineinfile:
    dest: /etc/httpd/conf/httpd.conf
    regexp: "^ExtendedStatus.*Off"
    line: "ExtendedStatus On"
  register: apache_server_extended_status

Giovanni