# creating directories (mkdir -p)

**URL:** <https://forum.ansible.com/t/creating-directories-mkdir-p/19803>\
**Category:** Ansible Project\
**Created:** [November 19, 2015, 8:44am UTC](https://forum.ansible.com/t/creating-directories-mkdir-p/19803 "2015-11-19T08:44:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bobby\_Billingsley](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@Bobby\_Billingsley](https://forum.ansible.com/u/Bobby_Billingsley)\
**Post date:** [November 19, 2015, 8:44am UTC](https://forum.ansible.com/t/creating-directories-mkdir-p/19803/1 "2015-11-19T08:44:18Z")

</div>

I’m trying to create a subdirectory (to a not-necessarily existing directory) and failing utterly ☹

So far I’ve tried:

- name: ensure config dir exists  
file: path={{base\_dir}}/config state=directory mode=0755  
tags: myprog,confdir

base\_dir is defined in the appropriate vars.yml:

base\_dir: /home/my/base

both of which give me the following output:

TASK: [ensure config dir exists] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [host01]  
changed: [host02]

This leads me to believe that the dir should’ve been created.

However, the next task in the play:

- name: ensure handy symlink exists  
file: src={{base\_dir}} dest=/mybase state=link  
tags: myprog,rootlink

fails miserably:

TASK: [ensure handy symlink exists] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [host01] =\> {“failed”: true, “path”: “/mybase”, “src”: “/home/my/base”, “state”: “absent”}  
msg: src file does not exist, use “force=yes” if you really want to create the link: /home/my/base  
failed: [host02] =\> {“failed”: true, “path”: “/mybase”, “src”: “/home/my/base”, “state”: “absent”}  
msg: src file does not exist, use “force=yes” if you really want to create the link: /home/my/base

so i tried a different tack:

- name: ensure config dir exists  
command: /bin/mkdir -p {{base\_dir}}/config creates={{base\_dir}}/config

tags: myprog,confdir

which also fails to do what I was expecting.

Checking the /home directory on both destinations reveals that no intermediate directories were created.

I’m stumped - any suggestions?

/bobby
