# Lineinfile always reporting changed

**URL:** <https://forum.ansible.com/t/lineinfile-always-reporting-changed/20631>\
**Category:** Ansible Project\
**Created:** [February 19, 2016, 1:30pm UTC](https://forum.ansible.com/t/lineinfile-always-reporting-changed/20631 "2016-02-19T13:30:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Austin\_Butler](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@Austin\_Butler](https://forum.ansible.com/u/Austin_Butler)\
**Post date:** [February 19, 2016, 1:30pm UTC](https://forum.ansible.com/t/lineinfile-always-reporting-changed/20631/1 "2016-02-19T13:30:24Z")

</div>

The lineinfile module is consistently reporting changed on a step. The actual replace works fine the first time, and it’s not harming anything on subsequent runs so I guess it’s mostly a cosmetic issue, but still I am trying to keep changes to, you know, actual changes.

I am wondering if this is from the variable used in the line file (“inventory\_hostname”). Any ideas? Or is this bug report worthy?

Version of Ansible: 2.0.0.2

Playbook snippet:

- name: configure hostname for checks

lineinfile:  
dest: ‘/etc/monit.d/system.conf’  
regexp: ‘^check system’  
line: ‘check system {{ inventory\_hostname }}’

Original file:

check system test  
if MEMORY \> 80% for 6 cycles then alert  
if LOADAVG(15min) \> 20 for 12 cycles then alert  
if SWAP \> 20% for 6 cycles then alert

File after first run (and all subsequent runs):

check system 192.168.50.3  
if MEMORY \> 80% for 6 cycles then alert  
if LOADAVG(15min) \> 20 for 12 cycles then alert  
if SWAP \> 20% for 6 cycles then alert

---

<div class="post-metadata">

**Author:** ![Jim\_Clausing](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@Jim\_Clausing](https://forum.ansible.com/u/Jim_Clausing)\
**Post date:** [February 20, 2016, 10:01pm UTC](https://forum.ansible.com/t/lineinfile-always-reporting-changed/20631/2 "2016-02-20T22:01:22Z")

</div>

Why wouldn’t it change it every time, your regex is looking for lines starting with ‘check system’, and even after the change the line still starts with that. I’m just getting started with ansible myself, so I don’t have a quick solution for you, but given the snippet you provided, that would be expected behavior.

—Jim

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [February 21, 2016, 2:35am UTC](https://forum.ansible.com/t/lineinfile-always-reporting-changed/20631/3 "2016-02-21T02:35:23Z")

</div>

I cannot reproduce this with the exact same files you provided.  
For me it works fine as expected with v1.9.4 and v2.0.0.2.  
Only the first run reports a change, subsequent runs return ok.

I wonder what might be different that could influence the behaviour.

---

<div class="post-metadata">

**Author:** ![Austin\_Butler](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@Austin\_Butler](https://forum.ansible.com/u/Austin_Butler)\
**Post date:** [August 5, 2016, 6:42am UTC](https://forum.ansible.com/t/lineinfile-always-reporting-changed/20631/4 "2016-08-05T06:42:10Z")

</div>

I get that it will match the search every time, but I guess it doesn’t see that it would be “changed” to the exact same text already there. AKA even if it matches, nothing actually changes. Maybe that’s how it’s supposed to work and I am just misunderstanding that, though.
