# unable to create directory using ansible file module

**URL:** <https://forum.ansible.com/t/unable-to-create-directory-using-ansible-file-module/32473>\
**Category:** Ansible Project\
**Created:** [March 16, 2020, 7:20am UTC](https://forum.ansible.com/t/unable-to-create-directory-using-ansible-file-module/32473 "2020-03-16T07:20:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shifa\_Shaikh](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Shifa\_Shaikh](https://forum.ansible.com/u/Shifa_Shaikh)\
**Post date:** [March 16, 2020, 7:20am UTC](https://forum.ansible.com/t/unable-to-create-directory-using-ansible-file-module/32473/1 "2020-03-16T07:20:21Z")

</div>

Here is my variable file:

cat vars.yml  
`

---

<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:** [March 16, 2020, 7:29am UTC](https://forum.ansible.com/t/unable-to-create-directory-using-ansible-file-module/32473/2 "2020-03-16T07:29:55Z")

</div>

Hi

you've missed a few basic things. The vars file contains a duplicate  
variable layers - that won't work.  
Also, you appear to want to loop over the variable layers, but you  
don't actually use it.  
Have a look at this URL, it has some nice examples of how loops work:

[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_loops.html#iterating-over-a-simple-list](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#iterating-over-a-simple-list)

---

<div class="post-metadata">

**Author:** ![Shifa\_Shaikh](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Shifa\_Shaikh](https://forum.ansible.com/u/Shifa_Shaikh)\
**Post date:** [March 16, 2020, 7:40am UTC](https://forum.ansible.com/t/unable-to-create-directory-using-ansible-file-module/32473/3 "2020-03-16T07:40:55Z")

</div>

Dick Hi, The issue is not with the loop as I can see the correct value populated using debug.

Aslo, the correct value shows up in the error output from the loop … see below:

`fatal: [localhost]: FAILED! => {"changed": false, "msg": "file (/tmp/dashboard/APP state=directory recurse=yes) is absent, cannot continue", "path": "/tmp/dashboard/APP state=directory recurse=yes"}`

/tmp/dashboard/APP is indeed the correct desired directory that should be created.

Please suggest.

---

<div class="post-metadata">

**Author:** ![Vivek\_Kothawale](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@Vivek\_Kothawale](https://forum.ansible.com/u/Vivek_Kothawale)\
**Post date:** [March 16, 2020, 7:56am UTC](https://forum.ansible.com/t/unable-to-create-directory-using-ansible-file-module/32473/4 "2020-03-16T07:56:39Z")

</div>

Hi shifa,

Can you please check whether dashboard dir is present on remote server?

Thanks,  
Vivek

---

<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:** [March 16, 2020, 7:56am UTC](https://forum.ansible.com/t/unable-to-create-directory-using-ansible-file-module/32473/5 "2020-03-16T07:56:42Z")

</div>

Ah OK yes, i see, you're right.  
The issue is your quoting, as indicated by the error message.  
Instead of:

&nbsp;&nbsp;&nbsp;- file: path="{{ playbook\_dir }}/dashboard/{{ my\_result.name }}  
state=directory recurse=yes"

Do this:

&nbsp;&nbsp;&nbsp;- file: path="{{ playbook\_dir }}/dashboard/{{ my\_result.name }}"  
state=directory recurse=yes

---

<div class="post-metadata">

**Author:** ![Shifa\_Shaikh](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Shifa\_Shaikh](https://forum.ansible.com/u/Shifa_Shaikh)\
**Post date:** [March 16, 2020, 8:44am UTC](https://forum.ansible.com/t/unable-to-create-directory-using-ansible-file-module/32473/6 "2020-03-16T08:44:57Z")

</div>

@Dick your suggestion helped !! it works.
