using wildcards to fetching src files

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

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
  action: command ls -1 /data_dump_*.sql
  register: dumpfiles
- name: fetch files
  action: fetch src=$item dest=/var/lib/ansible/files/fetched
  with_items: ${dumpfiles.stdout_lines}

Daniel

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

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

Which should have read:

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 :slight_smile:

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

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.