# lineinfile Questions

**URL:** <https://forum.ansible.com/t/lineinfile-questions/17518>\
**Category:** Ansible Project\
**Created:** [February 15, 2015, 8:56am UTC](https://forum.ansible.com/t/lineinfile-questions/17518 "2015-02-15T08:56:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doug\_Eubanks](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@Doug\_Eubanks](https://forum.ansible.com/u/Doug_Eubanks)\
**Post date:** [February 15, 2015, 8:56am UTC](https://forum.ansible.com/t/lineinfile-questions/17518/1 "2015-02-15T08:56:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 16, 2015, 2:57pm UTC](https://forum.ansible.com/t/lineinfile-questions/17518/2 "2015-02-16T14:57:02Z")

</div>

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

Please try this:

- name: set apache ExtendedStatus  
&nbsp;&nbsp;lineinfile:  
&nbsp;&nbsp;&nbsp;&nbsp;dest: /etc/httpd/conf/httpd.conf  
&nbsp;&nbsp;&nbsp;&nbsp;regexp: "^ExtendedStatus.\*Off"  
&nbsp;&nbsp;&nbsp;&nbsp;line: "ExtendedStatus On"  
&nbsp;&nbsp;register: apache\_server\_extended\_status

Giovanni
