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

36 views
Skip to first unread message

Rusty Roy

unread,
Jun 19, 2017, 11:35:29 AM6/19/17
to Ansible Project
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?

Brian Coca

unread,
Jun 19, 2017, 7:34:54 PM6/19/17
to Ansible Project
That is normal and expected behaviour, delete the file first


--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages