# File exists: '/home/travis/.fireball.keys'

**URL:** <https://forum.ansible.com/t/file-exists-home-travis-fireball-keys/14170>\
**Category:** Ansible Project\
**Created:** [December 17, 2013, 6:34pm UTC](https://forum.ansible.com/t/file-exists-home-travis-fireball-keys/14170 "2013-12-17T18:34:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathias\_Bogaert](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mathias\_Bogaert](https://forum.ansible.com/u/Mathias_Bogaert)\
**Post date:** [December 17, 2013, 6:34pm UTC](https://forum.ansible.com/t/file-exists-home-travis-fireball-keys/14170/1 "2013-12-17T18:34:32Z")

</div>

Hi,

I’m trying to get Ansible’s accelerated mode to work on Travis CI, but I’m getting

OSError: [Errno 17] File exists: ‘/home/travis/.fireball.keys’

See here: [https://travis-ci.org/analytically/hadoop-ansible/builds/15598716](https://travis-ci.org/analytically/hadoop-ansible/builds/15598716)

From the log we can see that the bootstrap of the servers on DO using Ansible works fine, bootstrapping using Ansible works fine, both source and target servers have python-keyczar installed. Any idea?

Thanks,

Mathias

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [December 19, 2013, 3:37pm UTC](https://forum.ansible.com/t/file-exists-home-travis-fireball-keys/14170/2 "2013-12-19T15:37:12Z")

</div>

Looking at the last build, it seems like this issue went away: [https://travis-ci.org/analytically/hadoop-ansible/builds/15680563](https://travis-ci.org/analytically/hadoop-ansible/builds/15680563)

Did you find a workaround?

---

<div class="post-metadata">

**Author:** ![Mathias\_Bogaert](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mathias\_Bogaert](https://forum.ansible.com/u/Mathias_Bogaert)\
**Post date:** [December 19, 2013, 3:38pm UTC](https://forum.ansible.com/t/file-exists-home-travis-fireball-keys/14170/3 "2013-12-19T15:38:06Z")

</div>

I’ve just disabled accelerated mode, the issue is still there.

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [December 19, 2013, 3:49pm UTC](https://forum.ansible.com/t/file-exists-home-travis-fireball-keys/14170/4 "2013-12-19T15:49:12Z")

</div>

This is the code where the exception occurs … key\_path = os.path.expanduser(“~/.fireball.keys”) if not os.path.exists(key\_path): os.makedirs(key\_path) key\_path = os.path.expanduser(“~/.fireball.keys/%s” % hostname) It does make a check before creating the directory, but perhaps you are running into some weird race condition? Do any of your inventory hosts share the same IP or ansible\_ssh\_host ?

---

<div class="post-metadata">

**Author:** ![Mathias\_Bogaert](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mathias\_Bogaert](https://forum.ansible.com/u/Mathias_Bogaert)\
**Post date:** [December 19, 2013, 3:50pm UTC](https://forum.ansible.com/t/file-exists-home-travis-fireball-keys/14170/5 "2013-12-19T15:50:59Z")

</div>

Strange. I’m creating new droplets on DigitalOcean, so they should have seperate IP’s.

---

<div class="post-metadata">

**Author:** ![Darragh\_Bailey](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@Darragh\_Bailey](https://forum.ansible.com/u/Darragh_Bailey)\
**Post date:** [January 13, 2016, 3:42pm UTC](https://forum.ansible.com/t/file-exists-home-travis-fireball-keys/14170/6 "2016-01-13T15:42:42Z")

</div>

We’ve recently run into this at work, and thought I’d point out the problem in case someone else stumbles across the issue.

There is a race, as the initial task (setup to gather facts) goes to be executed on multiple hosts, if the directory ~/.fireball.keys does not exist, there will be multiple attempts to create it, depending on where the GIL is interrupted to hand over control around [https://github.com/ansible/ansible/blob/62979efa140ce9659beac6442b51bd8efe35d4ba/lib/ansible/utils/encrypt.py#L98](https://github.com/ansible/ansible/blob/62979efa140ce9659beac6442b51bd8efe35d4ba/lib/ansible/utils/encrypt.py#L98)

When running multiple forks, each one can test that the directory does not exist, and attempt to create it. The first one that creates it will succeed without an issue, and the remainder will get an OSError that the file already exists.

Since for the Travis CI runs you get a pristine environment each time, you’ll see this occurring on a frequent basis. A simple fix is to ensure a single gather facts run is executed on only one of the target hosts using accelerate first, then follow this with the normal plays.

A fix in the ansible code base would be to wrap the mkdir either with a threading lock or with something like the following:

@contextlib.contextmanager  
def ignore\_oserror\_exists():  
try:  
yield  
except OSError as ose:  
if ose.errno != errno.EEXIST:  
raise ose

with ignore\_oserror\_exists():  
os.makedirs(key\_path, mode=0o700)

Will file an issue with ansible shortly.
