# using wildcards to fetching src files

**URL:** <https://forum.ansible.com/t/using-wildcards-to-fetching-src-files/12049>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [October 29, 2012, 8:03pm UTC](https://forum.ansible.com/t/using-wildcards-to-fetching-src-files/12049 "2012-10-29T20:03:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 29, 2012, 8:03pm UTC](https://forum.ansible.com/t/using-wildcards-to-fetching-src-files/12049/1 "2012-10-29T20:03:32Z")

</div>

Ansible 0.8 contains "with\_fileglob", which does what you want

action: modulename src=$item \<other arguments\>  
with\_fileglob: /data\_dump\_\*.sql

It would send over all files matching the glob from the local server  
in that case.

Looks like that will do exactly what you want.

--Michael

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [October 29, 2012, 8:37pm UTC](https://forum.ansible.com/t/using-wildcards-to-fetching-src-files/12049/2 "2012-10-29T20:37:36Z")

</div>

Michael DeHaan wrote:

> Ansible 0.8 contains "with\_fileglob", which does what you want
> 
> action: modulename src=$item \<other arguments\>  
> with\_fileglob: /data\_dump\_\*.sql
> 
> It would send over all files matching the glob from the local server  
> in that case.

However, when you want the opposite and you're using fetch, that is not  
going to work.

> Looks like that will do exactly what you want.
> 
> --Michael
> 
> > Hi all,
> > 
> > I'm trying to copy a files down from one of our hosts, and it contains a  
> > timestamp in the name. This, unfortunately, is going to be hard to  
> > change  
> > for us (if at all).
> > 
> > Is there a way in ansible to have a source file with a wildcard?
> > 
> > i.e.:
> > 
> > > action: fetch src=/data\_dump\_\*.sql dest=/var/lib/ansible/files/fetched

Yes, the way to do it is to list the files in one action, and then use  
with\_items on the result. For example  
- name: list files  
&nbsp;&nbsp;action: command ls -1 /data\_dump\_\*.sql  
&nbsp;&nbsp;register: dumpfiles  
- name: fetch files  
&nbsp;&nbsp;action: fetch src=$item dest=/var/lib/ansible/files/fetched  
&nbsp;&nbsp;with\_items: ${dumpfiles.stdout\_lines}

Daniel

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [October 29, 2012, 11:51pm UTC](https://forum.ansible.com/t/using-wildcards-to-fetching-src-files/12049/3 "2012-10-29T23:51:09Z")

</div>

What I usually do in this case, especially if you need to recurse over directories is:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 30, 2012, 12:26am UTC](https://forum.ansible.com/t/using-wildcards-to-fetching-src-files/12049/4 "2012-10-30T00:26:50Z")

</div>

I prefer Daniel's approach in this case, but I think we can also make syntax easier if using fetch by building a "with\_remote\_fileglob" if we wanted to.

-- Michael

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [October 30, 2012, 12:34am UTC](https://forum.ansible.com/t/using-wildcards-to-fetching-src-files/12049/5 "2012-10-30T00:34:52Z")

</div>

Which should have read:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 30, 2012, 12:37am UTC](https://forum.ansible.com/t/using-wildcards-to-fetching-src-files/12049/6 "2012-10-30T00:37:02Z")

</div>

The only disadvantage of shelling out to rsync is it assumes you have  
keys and such configured.

So if you're using paramiko with askpass, it is not a clean option.

However, if you are moving a large amount of data, it's definitely a  
great option, and most people will be using SSH-agent anyway.

Also: fetch is a minority of the use cases anyway 🙂

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [May 18, 2016, 7:50pm UTC](https://forum.ansible.com/t/using-wildcards-to-fetching-src-files/12049/7 "2016-05-18T19:50:31Z")

</div>

I am wondering if a remote fileglob mechanism has been added for fetch. If not, I’ll use Daniel’s solution from above.

Thanks!  
Joanna

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 18, 2016, 7:54pm UTC](https://forum.ansible.com/t/using-wildcards-to-fetching-src-files/12049/8 "2016-05-18T19:54:57Z")

</div>

instead of shell/ls, you can use the ‘find’ module to create the list and feed that to the ‘fetch’ module.

as for rsync, the syncronize module can handle many of the same scenarios.
