Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

race condition in directory creation using file module #1648

Closed
mjg123 opened this issue Jul 1, 2015 · 1 comment · Fixed by #1649
Closed

race condition in directory creation using file module #1648

mjg123 opened this issue Jul 1, 2015 · 1 comment · Fixed by #1649

Comments

@mjg123
Copy link

mjg123 commented Jul 1, 2015

Ansible 1.9.2 (also observed this issue on 1.7.2)

mybook.yml:


---
-
  hosts: all
  serial: 10
  tasks:
  -
    file:
      path: "/tmp/banana"
      state: "directory"

myhosts

lh0
lh1
lh2
lh3
lh4
lh5
lh6
lh7
lh8
lh9

NB all these are aliases of 127.0.0.1 in my /etc/localhosts

The following command will occasionally fail, in my experience about 5% failure rate, but YMMV:

rm -rf /tmp/banana ; ansible-playbook -i myhosts  mybook.yml
PLAY [all] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [lh4]
ok: [lh0]
ok: [lh3]
ok: [lh1]
ok: [lh2]
ok: [lh6]
ok: [lh5]
ok: [lh7]
ok: [lh8]
ok: [lh9]

TASK: [file ] ***************************************************************** 
changed: [lh3]
failed: [lh0] => {"failed": true, "parsed": false}
Traceback (most recent call last):
  File "/home/ubuntu/.ansible/tmp/ansible-tmp-1435747470.28-279212074405278/file", line 2005, in <module>
    main()
  File "/home/ubuntu/.ansible/tmp/ansible-tmp-1435747470.28-279212074405278/file", line 279, in main
    os.mkdir(curpath)
OSError: [Errno 17] File exists: '/tmp/banana'
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: auto-mux: Trying existing master
debug1: mux_client_request_session: master session id: 2
Shared connection to lh0 closed.

ok: [lh1]
ok: [lh2]
ok: [lh4]
ok: [lh5]
ok: [lh6]
ok: [lh7]
ok: [lh9]
ok: [lh8]

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/ubuntu/mybook.retry

lh0                        : ok=1    changed=0    unreachable=0    failed=1   
lh1                        : ok=2    changed=0    unreachable=0    failed=0   
lh2                        : ok=2    changed=0    unreachable=0    failed=0   
lh3                        : ok=2    changed=1    unreachable=0    failed=0   
lh4                        : ok=2    changed=0    unreachable=0    failed=0   
lh5                        : ok=2    changed=0    unreachable=0    failed=0   
lh6                        : ok=2    changed=0    unreachable=0    failed=0   
lh7                        : ok=2    changed=0    unreachable=0    failed=0   
lh8                        : ok=2    changed=0    unreachable=0    failed=0   
lh9                        : ok=2    changed=0    unreachable=0    failed=0   

I have been able to automate the triggering of this with:

true; while [ $? == 0 ]; do rm -rf /tmp/banana ; ansible-playbook -i myhosts  mybook.yml ; done
@mjg123
Copy link
Author

mjg123 commented Jul 1, 2015

Here's the offending code:

https://github.com/ansible/ansible-modules-core/blob/devel/files/file.py#L282-L283

This is not atomic.

mjg123 pushed a commit to mjg123/ansible-modules-core that referenced this issue Jul 1, 2015
If we try to make a directory, but someone else creates the directory
at the same time as us, we don't need to raise that error to the user.
They asked for the directory to exist, and now it does. This fixes
the race condition which was causing that error to be raised, and
closes ansible#1648.
mjg123 pushed a commit to mjg123/ansible-modules-core that referenced this issue Jul 1, 2015
If we try to make a directory, but someone else creates the directory
at the same time as us, we don't need to raise that error to the user.
They asked for the directory to exist, and now it does. This fixes
the race condition which was causing that error to be raised, and
closes ansible#1648.
mjg123 pushed a commit to mjg123/ansible-modules-core that referenced this issue Jul 1, 2015
If we try to make a directory, but someone else creates the directory
at the same time as us, we don't need to raise that error to the user.
They asked for the directory to exist, and now it does. This fixes
the race condition which was causing that error to be raised, and
closes ansible#1648.
mjg123 pushed a commit to mjg123/ansible-modules-core that referenced this issue Jul 1, 2015
If we try to make a directory, but someone else creates the directory
at the same time as us, we don't need to raise that error to the user.
They asked for the directory to exist, and now it does. This fixes
the race condition which was causing that error to be raised, and
closes ansible#1648.
@bcoca bcoca added the P2 label Jul 1, 2015
@bcoca bcoca added this to the v2 milestone Jul 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants