On Thu, 28 May 2020 22:14:35 -0700 (PDT) Amith sha <[email protected]> wrote:
> Tried to write a line using lineinfule module sequentially were observed > that the random lines are missed to write on the file. > > serial: 100 > > - name: Write Disks Data to file > lineinfile: ... > delegate_to: localhost > > EXPECTED RESULTS > Passed 4 ips to the inventory so 4 entries should be made on the file. > > ACTUAL RESULTS > Got 2 entries on the first attempt. > Got 4 entries on second attempt. 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 -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20200529081445.772c7fd9%40gmail.com.
pgpqd5FbEznrQ.pgp
Description: OpenPGP digital signature
