ansible-runner icon indicating copy to clipboard operation
ansible-runner copied to clipboard

Occasional no such file error with option rotate_artifacts=1

Open bzwei opened this issue 2 years ago • 3 comments

When calling ansible-runner python library to run a module with rotate_artifacts=1, we occasionally get no such file or directory:

  File "/root/test/ansible-rulebook/venv/lib/python3.9/site-packages/ansible_runner/interface.py", line 210, in run
    r.run()
  File "/root/test/ansible-rulebook/venv/lib/python3.9/site-packages/ansible_runner/runner.py", line 153, in run
    os.close(os.open(stdout_filename, os.O_CREAT, stat.S_IRUSR | stat.S_IWUSR))
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/run_module6zpse6zz/artifacts/b0fd06fb-bced-471c-9993-802f36b8a219/stdout'

Checking file directories, /tmp/run_module6zpse6zz/artifacts/b0fd06fb-bced-471c-9993-802f36b8a219 does not exist. The only artifact folder found is the leftover from last execution. Ansible runner deletes the wrong artifact.

To reproduce the error we executed the module from the same location repeatedly for many times.

bzwei avatar Nov 08 '22 19:11 bzwei

@bzwei Is this an Ansible Runner issue?

mkanoor avatar Nov 09 '22 03:11 mkanoor

@bzwei Is this an Ansible Runner issue?

Yes, I believe so. Please take a look.

bzwei avatar Nov 10 '22 14:11 bzwei

Hrm, the code used to rotate the artifact dirs uses mtime (modification time) of the artifact directories to sort/delete. Depending on timing, and even outside entities accessing that directory's contents, I could see where that might cause the problem you see. A better strategy might be to use ctime (creation time) AND add a safeguard to make sure we never delete the current artifact directory.

Shrews avatar Nov 15 '22 15:11 Shrews