# lineinfile module replace correctly for the first time run the playbook, but not the second time

**URL:** <https://forum.ansible.com/t/lineinfile-module-replace-correctly-for-the-first-time-run-the-playbook-but-not-the-second-time/22837>\
**Category:** Ansible Project\
**Created:** [October 20, 2016, 2:39am UTC](https://forum.ansible.com/t/lineinfile-module-replace-correctly-for-the-first-time-run-the-playbook-but-not-the-second-time/22837 "2016-10-20T02:39:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lee\_lyly](https://avatars.discourse-cdn.com/v4/letter/l/e8c25b/32.png) [@lee\_lyly](https://forum.ansible.com/u/lee_lyly)\
**Post date:** [October 20, 2016, 2:39am UTC](https://forum.ansible.com/t/lineinfile-module-replace-correctly-for-the-first-time-run-the-playbook-but-not-the-second-time/22837/1 "2016-10-20T02:39:24Z")

</div>

Below is the sample of the lineinfile module that I used. The first time run the playbook, it successfully change the line with the new line.  
However, after I run one more time the playbook, it still add the line at the bottom of the file.

> - name: Change abc  
> lineinfile:  
> dest: “{{ abc }}”  
> state: present  
> regexp: ’ http://{{ ansible\_fqdn }}:{{ wabc\_port }}’  
> line: ’ https://{{ ansible\_fqdn }}:{{ abc\_port\_https }}’

How should it works?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 21, 2016, 7:46pm UTC](https://forum.ansible.com/t/lineinfile-module-replace-correctly-for-the-first-time-run-the-playbook-but-not-the-second-time/22837/2 "2016-10-21T19:46:04Z")

</div>

[https://groups.google.com/d/msg/ansible-project/TLB5oveaYig/StqWoezVAwAJ](https://groups.google.com/d/msg/ansible-project/TLB5oveaYig/StqWoezVAwAJ)
