multiple changes using lineinfile

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)

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.