use fetch module with wild card or best way to grab different name file from several hosts

Hello,

I have created a log file using ansible an have named the log file with the host name. I need to fetch that file from all my hosts and put it in a directory on the control server. However, it runs fine but does not copy the files over. Here is my cmds.

  • name: “Find needsreboot.log file”
    find:
    paths: /dir/
    patterns: “*.needsreboot.log” I have also tried $HOSTNAME-needsreboot.log

-name:
fetch: src: /dir/*.needsreboot.log
dest: /dir on control server/logs
flat: yes

thank you,

fetch does not support wildcards, register the data from find and use
that in loop in fetch

So how would it look?

this explains it.
http://docs.ansible.com/ansible/latest/playbooks_variables.html#registered-variables

I’m pretty new to Ansible and I am doing something wrong when I try it with variables. All I get is errors now. and I have not even gotten to the loop part yet.

  • name: “check if files exsists”
    shell: /path/*-needsreboot.log
    register: log_result
    ignore_errors: True

shell:/path/
when: log_result.rc == 5

  • name: “Find needsreboot.log file”
    find:
    paths: /dir/
    patterns: “*.needsreboot.log” I have also tried $HOSTNAME-needsreboot.log

-name:
fetch: src: /dir/*.needsreboot.log I have also tried $HOSTNAME-needsreboot.log
dest: /dir on control server/logs
flat: yes

Could some one please help with an example of this and loop.

Changed to check the file exists

  • name: Make sure file exists
    file:
    path: /root/*-needsreboot.log
    state: touch

still need an example for fetch and loop if that is needed or variable and loop.