Error odule fetch dest is an existing directory

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,

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

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?

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

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.