# Error odule fetch dest is an existing directory

**URL:** <https://forum.ansible.com/t/error-odule-fetch-dest-is-an-existing-directory/37475>\
**Category:** Ansible Project\
**Created:** [December 16, 2022, 9:14pm UTC](https://forum.ansible.com/t/error-odule-fetch-dest-is-an-existing-directory/37475 "2022-12-16T21:14:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emanuel\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/e/b3f665/32.png) [@Emanuel\_Gonzalez](https://forum.ansible.com/u/Emanuel_Gonzalez)\
**Post date:** [December 16, 2022, 9:14pm UTC](https://forum.ansible.com/t/error-odule-fetch-dest-is-an-existing-directory/37475/1 "2022-12-16T21:14:51Z")

</div>

Hi, i use the fetch module to copy files from remote to local:

- delegate\_to: localhost  
become: false  
command: whoami  
register: local\_user

- name: “copy to local”  
fetch:  
src: “/tmp/file.bz2”  
dest: “/home/{{ local\_user.stdout }}”  
flat: true

I see this error:

The full traceback is:  
NoneType: None  
fatal: [server]: FAILED! =\> {  
“changed”: false,  
“msg”: “dest is an existing directory, use a trailing slash if you want to fetch src into that directory”  
}

I want to copy the file into my home folder (/home/user).

What am I doing wrong?

Regards,

---

<div class="post-metadata">

**Author:** ![shearn](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@shearn](https://forum.ansible.com/u/shearn)\
**Post date:** [December 16, 2022, 9:33pm UTC](https://forum.ansible.com/t/error-odule-fetch-dest-is-an-existing-directory/37475/2 "2022-12-16T21:33:27Z")

</div>

local\_user.stdout is a directory that exists. Do you want to replace the directory with a file named file.bz2?

If you are wanting to put the file inside the directory, then add a slash to {{ local\_user.stdout }}_SLASH_

dest: “/home/{{ local\_user.stdout }}/”

Regards,

Stan

---

<div class="post-metadata">

**Author:** ![Emanuel\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/e/b3f665/32.png) [@Emanuel\_Gonzalez](https://forum.ansible.com/u/Emanuel_Gonzalez)\
**Post date:** [December 16, 2022, 9:42pm UTC](https://forum.ansible.com/t/error-odule-fetch-dest-is-an-existing-directory/37475/3 "2022-12-16T21:42:57Z")

</div>

I try, but i see this

The full traceback is:  
Traceback (most recent call last):  
File “/usr/lib/python3/dist-packages/ansible/plugins/action/fetch.py”, line 176, in run  
f = open(to\_bytes(dest, errors=‘surrogate\_or\_strict’), ‘wb’)  
IsADirectoryError: [Errno 21] Es un directorio: b’/home/emanuel/file.bz2’  
fatal: [server]: FAILED! =\> {  
“changed”: false,  
“msg”: “Failed to fetch the file: [Errno 21] Es un directorio: b’/home/emanuel/file.bz2’”  
}

➜ emanuel ~ whoami  
emanuel

Any suggestions?

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [December 16, 2022, 9:58pm UTC](https://forum.ansible.com/t/error-odule-fetch-dest-is-an-existing-directory/37475/4 "2022-12-16T21:58:32Z")

</div>

The error is very clear: there is a directory with that name.  
Remove that first and then try again

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [December 16, 2022, 9:59pm UTC](https://forum.ansible.com/t/error-odule-fetch-dest-is-an-existing-directory/37475/5 "2022-12-16T21:59:02Z")

</div>

It looks like you already have a directory named “/home/emanuel/file.bz2”. You need to remove or rename the existing directory before you can create a file with that same name.
