# copy remote files to remote directory

**URL:** <https://forum.ansible.com/t/copy-remote-files-to-remote-directory/33541>\
**Category:** Ansible Project\
**Created:** [August 3, 2020, 7:19am UTC](https://forum.ansible.com/t/copy-remote-files-to-remote-directory/33541 "2020-08-03T07:19:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Wong](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Ed\_Wong](https://forum.ansible.com/u/Ed_Wong)\
**Post date:** [August 3, 2020, 7:19am UTC](https://forum.ansible.com/t/copy-remote-files-to-remote-directory/33541/1 "2020-08-03T07:19:45Z")

</div>

Hi,

I’d like to copy (on a remote system) a file from one directory to another.

What I’m doing is:

– tasks:  
– name: copy remote file to local  
fetch:  
src: “/etc/resolve.conf”  
dest": “/tmp/”  
owner: root  
group: root  
mode: ‘0644’  
flat: yes

- name:  
copy:  
src: “/tmp/resolve.conf”  
dest: “/chroot/etc/”  
owner: root  
group: root  
mode: ‘0644’

While this works, I’m wondering if there’s something a bit less indirect? I’ve looked at  
file: but it can only do symlinks(soft ,hard) and create directories and files. From what I see,  
it can’t copy a file from dir to another. Or have I misread something?

Thanks

Ed

---

<div class="post-metadata">

**Author:** ![Ed\_Wong](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Ed\_Wong](https://forum.ansible.com/u/Ed_Wong)\
**Post date:** [August 3, 2020, 7:44am UTC](https://forum.ansible.com/t/copy-remote-files-to-remote-directory/33541/2 "2020-08-03T07:44:27Z")

</div>

I somehow missed remote\_src. My apologies.

---

<div class="post-metadata">

**Author:** ![lakshminarayanan\_R](https://avatars.discourse-cdn.com/v4/letter/l/f6c823/32.png) [@lakshminarayanan\_R](https://forum.ansible.com/u/lakshminarayanan_R)\
**Post date:** [August 3, 2020, 7:45am UTC](https://forum.ansible.com/t/copy-remote-files-to-remote-directory/33541/3 "2020-08-03T07:45:11Z")

</div>

Hi,  
fetch module doesn’t owner and group parameters, please revisit the ansible-doc.

EXAMPLES:

- name: Store file into /tmp/fetched/[host.example.com/tmp/somefile](http://host.example.com/tmp/somefile)  
fetch:  
src: /tmp/somefile  
dest: /tmp/fetched

- name: Specifying a path directly  
fetch:  
src: /tmp/somefile  
dest: /tmp/prefix-{{ inventory\_hostname }}  
flat: yes

- name: Specifying a destination path  
fetch:  
src: /tmp/uniquefile  
dest: /tmp/special/  
flat: yes

- name: Storing in a path relative to the playbook  
fetch:  
src: /tmp/uniquefile  
dest: special/prefix-{{ inventory\_hostname }}  
flat: yes

Thanks  
Lakshminarayanan. R

---

<div class="post-metadata">

**Author:** ![lakshminarayanan\_R](https://avatars.discourse-cdn.com/v4/letter/l/f6c823/32.png) [@lakshminarayanan\_R](https://forum.ansible.com/u/lakshminarayanan_R)\
**Post date:** [August 3, 2020, 7:48am UTC](https://forum.ansible.com/t/copy-remote-files-to-remote-directory/33541/4 "2020-08-03T07:48:30Z")

</div>

no problem
