# Fetch Files Based On Find Pattern

**URL:** <https://forum.ansible.com/t/fetch-files-based-on-find-pattern/28208>\
**Category:** Ansible Project\
**Created:** [July 31, 2018, 11:46am UTC](https://forum.ansible.com/t/fetch-files-based-on-find-pattern/28208 "2018-07-31T11:46:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaun\_Glass](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Shaun\_Glass](https://forum.ansible.com/u/Shaun_Glass)\
**Post date:** [July 31, 2018, 11:46am UTC](https://forum.ansible.com/t/fetch-files-based-on-find-pattern/28208/1 "2018-07-31T11:46:27Z")

</div>

Good Day,

We are running audit scripts on all of our servers. The results are in a .tar.gz file on each server with the servername-date-time included. I am running the following to pull the files from the servers but without success :

`

- hosts: one  
become: yes  
become\_method: sudo  
tasks:
- name: Find Audit Results  
find:  
paths: /root/  
patterns: “{{ inventory\_hostname }}\*.tar.gz”  
use\_regex: True  
recurse: no  
register: results
- name: Copy Audit Results From Servers  
fetch:  
src: “{{ path.item }}”  
dest: /home/shaun/Audit  
fail\_on\_missing: yes  
flat: yes  
with\_items: “{{ results.files }}”  
`

It executes without error but does not retrieve the files. Can anyone assist ?

Regards

Shaun

---

<div class="post-metadata">

**Author:** ![S\_C\_Rigler](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@S\_C\_Rigler](https://forum.ansible.com/u/S_C_Rigler)\
**Post date:** [July 31, 2018, 11:56am UTC](https://forum.ansible.com/t/fetch-files-based-on-find-pattern/28208/2 "2018-07-31T11:56:32Z")

</div>

You can probably consolidate both of those tasks into a single pull mode synchronize task.

–Steve

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 31, 2018, 12:51pm UTC](https://forum.ansible.com/t/fetch-files-based-on-find-pattern/28208/3 "2018-07-31T12:51:48Z")

</div>

You set use\_regex to true but your patterens is not a vaild regex, it's glob or shell as the Ansible find module is calling it.  
Remove the use\_regex or set it to False and it should work.

If you still want to use regex this is the correct syntax.

&nbsp;&nbsp;&nbsp;patterns: "{{ inventory\_hostname }}.\*\.tar\.gz"

---

<div class="post-metadata">

**Author:** ![Shaun\_Glass](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Shaun\_Glass](https://forum.ansible.com/u/Shaun_Glass)\
**Post date:** [August 1, 2018, 6:29am UTC](https://forum.ansible.com/t/fetch-files-based-on-find-pattern/28208/4 "2018-08-01T06:29:56Z")

</div>

Thanks very much …
