Fetch Files Based On Find Pattern

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

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

–Steve

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.

   patterns: "{{ inventory_hostname }}.*\.tar\.gz"

Thanks very much …