Error odule fetch dest is an existing directory

237 views
Skip to first unread message

SysAdmin EM

unread,
Dec 16, 2022, 4:15:40 PM12/16/22
to ansible...@googlegroups.com
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,

Hearn, Stan J.

unread,
Dec 16, 2022, 4:33:39 PM12/16/22
to ansible...@googlegroups.com

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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGUDtn%3DvGmxjFqKZ8khvYZoJ0M%2BUR_i_-z99Zha8_nZoTDTZLA%40mail.gmail.com.

SysAdmin EM

unread,
Dec 16, 2022, 4:43:57 PM12/16/22
to ansible...@googlegroups.com
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?



Dick Visser

unread,
Dec 16, 2022, 4:58:55 PM12/16/22
to ansible...@googlegroups.com
The error is very clear: there is a directory with that name.
Remove that first and then try again 



--
Sent from Gmail Mobile

Todd Lewis

unread,
Dec 16, 2022, 4:59:02 PM12/16/22
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages