# file ... directory only created on 2nd run

**URL:** <https://forum.ansible.com/t/file-directory-only-created-on-2nd-run/36232>\
**Category:** Ansible Project\
**Created:** [January 21, 2022, 8:45am UTC](https://forum.ansible.com/t/file-directory-only-created-on-2nd-run/36232 "2022-01-21T08:45:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [January 21, 2022, 8:45am UTC](https://forum.ansible.com/t/file-directory-only-created-on-2nd-run/36232/1 "2022-01-21T08:45:54Z")

</div>

I have this TASK in a roles tasks/main.yml

it reliably (almost 100% of the occassions I’d say) fails to create the directory ‘data’ on the 1st run of the playbook.  
Also with 100% reliabilty it succeeds with this on a 2nd run

- name: create db dirs  
file:  
path: “{{ db\_base }}/{{ item }}”  
state: directory  
owner: root  
become: yes  
loop:
- data
- backup

a missing backup dir does not cause an error directly following playbook TASKS, bust still it seems to me it gets created on the first round most of the times.

any idea what could be causing such a behaviour?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [January 21, 2022, 9:27am UTC](https://forum.ansible.com/t/file-directory-only-created-on-2nd-run/36232/2 "2022-01-21T09:27:18Z")

</div>

Depends on what the actual failure is, you didn’t provide any error details.

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [January 21, 2022, 10:19am UTC](https://forum.ansible.com/t/file-directory-only-created-on-2nd-run/36232/3 "2022-01-21T10:19:13Z")

</div>

the file TASK itself messages sucessful execution

2022-01-21 10:45:26,850 p=1753880 u=gwagner n=ansible | TASK [resize\_vgsys\_mariadb : create mariadb ‘backup’ & ‘data’ dirs] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
2022-01-21 10:45:27,140 p=1753880 u=gwagner n=ansible | changed: [vm-51150-0198.intern] =\> (item=/opt/db/backup/mysql)  
2022-01-21 10:45:27,383 p=1753880 u=gwagner n=ansible | **changed** : [vm-51150-0198.intern] =\> (item= **/opt/db/data/mysq** l)

later on another TASK complains about the missing directory

TASK [mariadb\_install : prepare install - cp my.cnf \>\> /opt/db/data/mysql/] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [vm-51150-0198.intern] (item=my.cnf) =\> changed=false  
ansible\_loop\_var: item  
item: my.cnf  
msg: Destination directory **/opt/db/data/mysql** does not exist

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [January 21, 2022, 10:41am UTC](https://forum.ansible.com/t/file-directory-only-created-on-2nd-run/36232/4 "2022-01-21T10:41:37Z")

</div>

Put a task just before that, with some debug for instance a directory listing so you can check if it’s really there or permission issues etc

Otherwise looks like a race condition in your playbook

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [January 21, 2022, 12:48pm UTC](https://forum.ansible.com/t/file-directory-only-created-on-2nd-run/36232/5 "2022-01-21T12:48:07Z")

</div>

The output you posted - with items “/opt/db/backup/mysql” and “/opt/db/data/mysql” - is not from the task you posted previously. That task had items “backup” and “data”.

Either you’ve inadvertently confused which steps are doing what, or you’ve left out relevant details in a kind but unsuccessful attempt to minimize your post for our benefit. If the latter, please, more detail is always better than more posts asking for additional detail.

It appears to me you’ve left out something, possibly relevant, between creation of /opt/db/{backup,data} and /opt/db/{backup,data}/mysql.
