# Creating directory using module file (state=directory).

**URL:** <https://forum.ansible.com/t/creating-directory-using-module-file-state-directory/18073>\
**Category:** Ansible Project\
**Created:** [April 24, 2015, 10:09am UTC](https://forum.ansible.com/t/creating-directory-using-module-file-state-directory/18073 "2015-04-24T10:09:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wojciech\_Korzenny](https://avatars.discourse-cdn.com/v4/letter/w/eada6e/32.png) [@Wojciech\_Korzenny](https://forum.ansible.com/u/Wojciech_Korzenny)\
**Post date:** [April 24, 2015, 10:09am UTC](https://forum.ansible.com/t/creating-directory-using-module-file-state-directory/18073/1 "2015-04-24T10:09:51Z")

</div>

Hi,

I have following playbook:

- hosts: group1  
user: ansible\_user  
gather\_facts: no  
tasks:
- name: Create backup directory  
file: path={{backup\_app\_logs\_dir}} state=directory

The problem is that group1 consists of more than 1 hosts. So create-directory action is executed on all of boxes the same time. I suspect that module check first if directory exists. If so, skip creating, otherwise perform mkdir. When more than 1 host get information “Perfrom mkdir”, they do it. First of them makes directory successfully, but next one fails because the directory shouldn’t be there according to verficiation:

Traceback (most recent call last):  
File “/tmp/ansible-tmp-1429781323.08-188650158471467/file”, line 1993, in ?  
main()  
File “/tmp/ansible-tmp-1429781323.08-188650158471467/file”, line 278, in main  
os.mkdir(curpath)  
OSError: [Errno 17] File exists: ‘/path/to/backup/directory’

I can of course skip this error and go forward by setting ignore\_errors to True (as I described above - my directory is created) but when I do the same action on multile host\_groups, first errors stops the task so next groups are not handled at all.

Do you see any easy solution not to split it into two different playbooks?

Regards,  
W.

---

<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:** [April 24, 2015, 1:38pm UTC](https://forum.ansible.com/t/creating-directory-using-module-file-state-directory/18073/2 "2015-04-24T13:38:04Z")

</div>

I'm guessing that the directory is in a shared drive across the hosts?  
if so I would suggest adding run\_once: True to your play.
