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