lineinfile Questions

29 views
Skip to first unread message

Doug Eubanks

unread,
Feb 15, 2015, 3:56:38 AM2/15/15
to ansible...@googlegroups.com
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

Giovanni Tirloni

unread,
Feb 16, 2015, 9:57:13 AM2/16/15
to ansible...@googlegroups.com
On Sun, 15 Feb 2015 00:56 -0800, Doug Eubanks <ad...@dougware.net>
wrote:
> 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 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
Reply all
Reply to author
Forward
0 new messages