# Concurrency Issue in a multi-node case with NFS drive mounted.

**URL:** <https://forum.ansible.com/t/concurrency-issue-in-a-multi-node-case-with-nfs-drive-mounted/19403>\
**Category:** Ansible Project\
**Created:** [October 1, 2015, 2:56pm UTC](https://forum.ansible.com/t/concurrency-issue-in-a-multi-node-case-with-nfs-drive-mounted/19403 "2015-10-01T14:56:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pratik\_Dhandharia](https://avatars.discourse-cdn.com/v4/letter/p/8baadc/32.png) [@Pratik\_Dhandharia](https://forum.ansible.com/u/Pratik_Dhandharia)\
**Post date:** [October 1, 2015, 2:56pm UTC](https://forum.ansible.com/t/concurrency-issue-in-a-multi-node-case-with-nfs-drive-mounted/19403/1 "2015-10-01T14:56:44Z")

</div>

I have a multi-node setup where I am using ansible to perform certain action. There exist a NFS mounted directory which is shared between the nodes.

I am having unexpected behaviour when the ansible tries to modify the same file from different nodes.

For example: Node01, Node02, Node03

File resides in: /home/demouser/test.txt (/home/demouser is nfs mounted and shared across all the nodes.)

My ansible script is something like this: (Ansible Version 1.8.4)

- hosts: all tasks:
- name: executing shell command
- shell: echo “test” \>\> /home/demouser/demotmp.txt | uniq \> /home/demouser/demotmp\_unique.txt | cp /tmp/demotmp\_unique.txt /home/demouser/test.txt

Occassionally I get a scenario when the updated file is empty. My guess is, this happens as ansible tries to modify the file on all nodes at roughly the same time.

Is there a module which allows locking a file? Or is there a better way to do this?

Thanks

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 2, 2015, 5:36am UTC](https://forum.ansible.com/t/concurrency-issue-in-a-multi-node-case-with-nfs-drive-mounted/19403/2 "2015-10-02T05:36:16Z")

</div>

I would expect this, don't update the same file from multiple nodes,  
use run\_once: True on the task to have a single node do it, otherwise  
you'll get this type of race condition.

modules do not lock as they normally execute on diff servers, also  
locking in this case would be counter productive, you'll have multiple  
processes on diff machines competing with each other and then  
replacing the same file over and over.
