# Ansible won't create dir when file exists with same name

**URL:** <https://forum.ansible.com/t/ansible-wont-create-dir-when-file-exists-with-same-name/24753>\
**Category:** Ansible Project\
**Tags:** windows, ubuntu\
**Created:** [June 17, 2017, 7:13pm UTC](https://forum.ansible.com/t/ansible-wont-create-dir-when-file-exists-with-same-name/24753 "2017-06-17T19:13:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rusty\_Roy](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@Rusty\_Roy](https://forum.ansible.com/u/Rusty_Roy)\
**Post date:** [June 17, 2017, 7:13pm UTC](https://forum.ansible.com/t/ansible-wont-create-dir-when-file-exists-with-same-name/24753/1 "2017-06-17T19:13:58Z")

</div>

I have the following task:

`

- name: create tmp dir to copy db sql to  
file: path=/tmp/sql state=directory  
`

When I run it, I get the error:

`  
TASK [mysql-data : create tmp dir to copy db sql to] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [default]: FAILED! =\> {“changed”: false, “failed”: true, “gid”: 0, “group”: “root”, “mode”: “0644”, “msg”: “/tmp/sql already exists as a file”, “owner”: “root”, “path”: “/tmp/sql”, “size”: 794097, “state”: “file”, “uid”: 0}

`

The file /tmp/sql does exist, so the error is correct in that /tmp/sql already exists as a file, but in the task I’m specifying that the directory /tmp/sql should exist, not a file (and if it did exist it shouldn’t be throwing an error anyway).

This is with ansible 2.3.1.0 and python version = 2.7.6 on an Ubuntu 14.04.5 VM. (On a windows host, but /tmp isn’t mapped to the host file system).

Anyone know what the problem is?

---

<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:** [June 19, 2017, 11:34pm UTC](https://forum.ansible.com/t/ansible-wont-create-dir-when-file-exists-with-same-name/24753/2 "2017-06-19T23:34:42Z")

</div>

That is normal and expected behaviour, delete the file first
