# multiple changes using lineinfile

**URL:** <https://forum.ansible.com/t/multiple-changes-using-lineinfile/19376>\
**Category:** Ansible Project\
**Created:** [September 29, 2015, 11:02am UTC](https://forum.ansible.com/t/multiple-changes-using-lineinfile/19376 "2015-09-29T11:02:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santosh\_Jambhlikar](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Santosh\_Jambhlikar](https://forum.ansible.com/u/Santosh_Jambhlikar)\
**Post date:** [September 29, 2015, 11:02am UTC](https://forum.ansible.com/t/multiple-changes-using-lineinfile/19376/1 "2015-09-29T11:02:54Z")

</div>

I am trying to make 2 different changes in one file but only last change is getting updated … Looks like ansible holds the file in memory (after first change) and never dump it back to disk as it knows there is/are more change (s) to be made as per .yml file. so when it is making change (second) in the same file (but on disks ) and while processing it , file in memory is getting replaced with newer version. So first change was done but never closed/completed/dumped back to disk.

There should be some mechanism to ‘close’ the file after each change but did not see it on ansible docs. Anyone aware?

P.S. - The same be accomplished by using different tasks but i don’t want to use (may need 15-20 changes in a file so don’t want same number of tasks)

---

<div class="post-metadata">

**Author:** ![Santosh\_Jambhlikar](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Santosh\_Jambhlikar](https://forum.ansible.com/u/Santosh_Jambhlikar)\
**Post date:** [September 29, 2015, 5:48pm UTC](https://forum.ansible.com/t/multiple-changes-using-lineinfile/19376/2 "2015-09-29T17:48:54Z")

</div>

Please note: there are 2 different changes (otherwise i could have written it - and it works) . first change is to replace a line and the another one is insert a line but on the same file.
