# creating a directory

**URL:** <https://forum.ansible.com/t/creating-a-directory/11831>\
**Category:** Ansible Project\
**Created:** [August 26, 2012, 2:13pm UTC](https://forum.ansible.com/t/creating-a-directory/11831 "2012-08-26T14:13:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![James8](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@James8](https://forum.ansible.com/u/James8)\
**Post date:** [August 26, 2012, 2:13pm UTC](https://forum.ansible.com/t/creating-a-directory/11831/1 "2012-08-26T14:13:08Z")

</div>

Hi,

I have tried this a bunch of different ways, I'm just posting my last  
version. Wondering if this is working as expected. I want to create  
a directory using the command module and it will create it if I take  
the second play out of the playbook. But when the directory doesn't  
exsist and both plays are in the playbook it fails on the copy. Is  
this a bug or am I missing some basic thing? I have tried this with  
and without the creates option and with and with out a chdir.

Thanks,  
James

sheepchase:tasks jmarcus$ cat backup.citrusleaf.conf.yml  
- hosts: CL801  
&nbsp;&nbsp;user: jmarcus  
&nbsp;&nbsp;sudo: True

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;- name: Make sure that the ansible\_backup directory exsists  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action: command mkdir /etc/citrusleaf/AnsibleBackup  
creates=/etc/citrusleaf/ansible\_backup

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;- name: Copy citrusleaf.conf before changing it  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action: shell cp /etc/citrusleaf/citrusleaf.conf  
/etc/citrusleaf/AnsibleBackup/citrusleaf.conf.`date +%F.%H:%M:%S`

sheepchase:tasks jmarcus$ ansible-playbook backup.citrusleaf.conf.yml  
-u jmarcus -K  
sudo password:

PLAY [CL801] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [cl801.domain.net]

TASK: [Copy citrusleaf.conf before changing it] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [cl801.domain.net] =\> {"changed": true, "cmd": "cp  
/etc/citrusleaf/citrusleaf.conf  
/etc/citrusleaf/AnsibleBackup/citrusleaf.conf.`date +%F.%H:%M:%S` ",  
"delta": "0:00:00.005314", "end": "2012-08-26 09:07:02.950212", "rc":  
1, "start": "2012-08-26 09:07:02.944898", "stderr": "cp: cannot create  
regular file `/etc/citrusleaf/AnsibleBackup/citrusleaf.conf.2012-08-26.09:07:02':  
No such file or directory", "stdout": ""}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
cl801.domain.net : ok=1 changed=0 unreachable=0 failed=1

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 26, 2012, 2:29pm UTC](https://forum.ansible.com/t/creating-a-directory/11831/2 "2012-08-26T14:29:26Z")

</div>

Would anyone like to guess what's different about these two directory paths?

> > mkdir /etc/citrusleaf/AnsibleBackup creates=/etc/citrusleaf/ansible\_backup

That's right, they aren't the same.

you can also be using the file module with state=directory.

Further, in 0.7, the copy and template module have a backup mode.

---

<div class="post-metadata">

**Author:** ![James8](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@James8](https://forum.ansible.com/u/James8)\
**Post date:** [August 26, 2012, 3:05pm UTC](https://forum.ansible.com/t/creating-a-directory/11831/3 "2012-08-26T15:05:44Z")

</div>

sorry I corrected that. I copied into the email before changing that,  
I'll give state= a try.

Thanks,  
james

---

<div class="post-metadata">

**Author:** ![Mark\_Theunissen](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@Mark\_Theunissen](https://forum.ansible.com/u/Mark_Theunissen)\
**Post date:** [August 26, 2012, 3:17pm UTC](https://forum.ansible.com/t/creating-a-directory/11831/4 "2012-08-26T15:17:24Z")

</div>

Hi James,

You also have two "tasks: " sections, is there a reason for that? I’m not sure that’s valid syntax, just use one “tasks:” and then put your actions below. You’re also missing the — which I believe YAML requires. And try using the file with state=directory:
