# Issue with lineinfile module #69739

**URL:** <https://forum.ansible.com/t/issue-with-lineinfile-module-69739/33045>\
**Category:** Ansible Project\
**Created:** [May 29, 2020, 5:14am UTC](https://forum.ansible.com/t/issue-with-lineinfile-module-69739/33045 "2020-05-29T05:14:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amith\_sha](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Amith\_sha](https://forum.ansible.com/u/Amith_sha)\
**Post date:** [May 29, 2020, 5:14am UTC](https://forum.ansible.com/t/issue-with-lineinfile-module-69739/33045/1 "2020-05-29T05:14:35Z")

</div>

##### SUMMARY

Tried to write a line using lineinfule module sequentially were observed that the random lines are missed to write on the file.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [May 29, 2020, 6:14am UTC](https://forum.ansible.com/t/issue-with-lineinfile-module-69739/33045/2 "2020-05-29T06:14:45Z")

</div>

It's a "race". Yes. This might be viewed as Python bug. This simply does not  
work in Python. See [https://en.wikipedia.org/wiki/Race\_condition](https://en.wikipedia.org/wiki/Race_condition)

It's been discussed and tested. See  
[https://groups.google.com/forum/#!topic/ansible-project/3DvVtiynMRU](https://groups.google.com/forum/#!topic/ansible-project/3DvVtiynMRU)

The remedy is simple. Use template and set "run\_once: true". If you insist on  
lineinfile use "throttle: 1" to serialize the writing to a file. The  
inefficiency compared to template is obvious.  
[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_strategies.html#using-keywords-to-control-execution](https://docs.ansible.com/ansible/latest/user_guide/playbooks_strategies.html#using-keywords-to-control-execution)

IMHO, there is nothing Ansible can do about it. Except probably to mention  
"race" when "throttle" is described in "Using keywords to control execution"

&nbsp;&nbsp;"This can be useful in restricting tasks that may be CPU-intensive or  
&nbsp;&nbsp;interact with a rate-limiting API"

I've submitted PR  
[https://github.com/ansible/ansible/commit/7f79b5942abeb2593cb83021c2470d6da7bc992e](https://github.com/ansible/ansible/commit/7f79b5942abeb2593cb83021c2470d6da7bc992e)

&nbsp;&nbsp;"This can be useful in restricting tasks that may be CPU-intensive,  
&nbsp;&nbsp;interact with a rate-limiting API, or access a critical section"

[https://github.com/ansible/ansible/issues/69739#issuecomment-635771688](https://github.com/ansible/ansible/issues/69739#issuecomment-635771688)

HTH,

&nbsp;&nbsp;-vlado
