# Get file(s) from a remote host to local host

**URL:** <https://forum.ansible.com/t/get-file-s-from-a-remote-host-to-local-host/31310>\
**Category:** Ansible Project\
**Created:** [September 18, 2019, 6:31pm UTC](https://forum.ansible.com/t/get-file-s-from-a-remote-host-to-local-host/31310 "2019-09-18T18:31:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![R-JRI](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@R-JRI](https://forum.ansible.com/u/R-JRI)\
**Post date:** [September 18, 2019, 6:31pm UTC](https://forum.ansible.com/t/get-file-s-from-a-remote-host-to-local-host/31310/1 "2019-09-18T18:31:17Z")

</div>

Hi,

I created a simple yml file to get file or files from a remote host to local host:  
$ cat fetch.yml

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 18, 2019, 8:51pm UTC](https://forum.ansible.com/t/get-file-s-from-a-remote-host-to-local-host/31310/2 "2019-09-18T20:51:17Z")

</div>

Your issue is that Apps\_files.files is a list, so Apps\_files[0].path  
would access the path of the FIRST file in that list, which means you  
have to extract path for each item to make the fetch loop work:

- name:  
&nbsp;&nbsp;fetch:  
&nbsp;&nbsp;&nbsp;&nbsp;src: "{{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;dest: /APPADMIN/ansible/nonprod/DR\_test/  
&nbsp;&nbsp;&nbsp;loop: "{{ Apps\_files.files|map(attribute='path')|list }}"

---

<div class="post-metadata">

**Author:** ![R-JRI](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@R-JRI](https://forum.ansible.com/u/R-JRI)\
**Post date:** [September 19, 2019, 5:10pm UTC](https://forum.ansible.com/t/get-file-s-from-a-remote-host-to-local-host/31310/3 "2019-09-19T17:10:06Z")

</div>

Thanks, Brian

That works.
