SUMMARY
Tried to write a line using lineinfule module sequentially were observed that the random lines are missed to write on the file.
Tried to write a line using lineinfule module sequentially were observed that the random lines are missed to write on the file.
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
It's been discussed and tested. See
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
IMHO, there is nothing Ansible can do about it. Except probably to mention
"race" when "throttle" is described in "Using keywords to control execution"
"This can be useful in restricting tasks that may be CPU-intensive or
interact with a rate-limiting API"
I've submitted PR
https://github.com/ansible/ansible/commit/7f79b5942abeb2593cb83021c2470d6da7bc992e
"This can be useful in restricting tasks that may be CPU-intensive,
interact with a rate-limiting API, or access a critical section"
https://github.com/ansible/ansible/issues/69739#issuecomment-635771688
HTH,
-vlado