# copy files from remote to local

**URL:** <https://forum.ansible.com/t/copy-files-from-remote-to-local/30690>\
**Category:** Ansible Project\
**Created:** [July 1, 2019, 1:19pm UTC](https://forum.ansible.com/t/copy-files-from-remote-to-local/30690 "2019-07-01T13:19:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_Kolan](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@Rahul\_Kolan](https://forum.ansible.com/u/Rahul_Kolan)\
**Post date:** [July 1, 2019, 1:19pm UTC](https://forum.ansible.com/t/copy-files-from-remote-to-local/30690/1 "2019-07-01T13:19:21Z")

</div>

Team,

Can someone provide me solution to copy all source /tmp/\*.exe files to local Ansible machine.

I tried below solution but its not working.

- name: example copying file with owner and permissions  
fetch:  
src: /tmp/\*.exe  
dest: /tmp/test/  
flat: yes  
owner: root  
group: root  
mode: 0777

---

<div class="post-metadata">

**Author:** ![Sudheer\_S1](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@Sudheer\_S1](https://forum.ansible.com/u/Sudheer_S1)\
**Post date:** [July 1, 2019, 1:24pm UTC](https://forum.ansible.com/t/copy-files-from-remote-to-local/30690/2 "2019-07-01T13:24:28Z")

</div>

Please describe what do you mean by not working. Do you get any error message? Describe the expected and actual results.

---

<div class="post-metadata">

**Author:** ![P.Cookson](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@P.Cookson](https://forum.ansible.com/u/P.Cookson)\
**Post date:** [July 1, 2019, 2:40pm UTC](https://forum.ansible.com/t/copy-files-from-remote-to-local/30690/3 "2019-07-01T14:40:50Z")

</div>

Based on v2.8, I don’t think you can wildcard filenames with fetch and it doesn’t seem to have owner, group or mode parameters (like copy) either. I think this discussion about a “wrapper” script or using the alternative synchronise module may help with your particular query though?:

[https://serverfault.com/questions/691080/how-to-fetch-multiple-files-from-remote-machine-to-local-with-ansible](https://serverfault.com/questions/691080/how-to-fetch-multiple-files-from-remote-machine-to-local-with-ansible)

Also, this link with all module details:

[https://docs.ansible.com/ansible/latest/modules/list\_of\_all\_modules.html](https://docs.ansible.com/ansible/latest/modules/list_of_all_modules.html)

Regards

Phil

---

<div class="post-metadata">

**Author:** ![Rahul\_Kolan](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@Rahul\_Kolan](https://forum.ansible.com/u/Rahul_Kolan)\
**Post date:** [July 1, 2019, 4:29pm UTC](https://forum.ansible.com/t/copy-files-from-remote-to-local/30690/4 "2019-07-01T16:29:12Z")

</div>

Hi ,

&nbsp;&nbsp;Thanks, following syntax worked for me.

- name: use find to get the files list which you want to copy/fetch  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;find:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paths: /tmp/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;patterns: ".\*exe"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;use\_regex: True  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: file\_2\_fetch

&nbsp;&nbsp;&nbsp;&nbsp;- name: use fetch to get the files  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fetch:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: "{{ item.path }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flat: yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: "{{ file\_2\_fetch.files }}"

\*Thanks & Regards,\*  
\*Rahul Kolan\*

\*DISCLAIMER: \*  
This message including attachments if any intended solely for specific  
individual and purpose & may contain confidential material AND/OR Private  
Company Information. If you are not the intended recipient, any disclosure,  
copying or distribution of this message or any action based on it, is  
strictly prohibited & protected under relevant law. If you have received  
this communication in error, please contact the sender or delete this  
message immediately. Thank you for your kind cooperation.
