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

**URL:** <https://forum.ansible.com/t/use-fetch-module-with-wild-card-or-best-way-to-grab-different-name-file-from-several-hosts/25903>\
**Category:** Ansible Project\
**Created:** [November 2, 2017, 5:42pm UTC](https://forum.ansible.com/t/use-fetch-module-with-wild-card-or-best-way-to-grab-different-name-file-from-several-hosts/25903 "2017-11-02T17:42:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kent\_Younge](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kent\_Younge](https://forum.ansible.com/u/Kent_Younge)\
**Post date:** [November 2, 2017, 5:42pm UTC](https://forum.ansible.com/t/use-fetch-module-with-wild-card-or-best-way-to-grab-different-name-file-from-several-hosts/25903/1 "2017-11-02T17:42:31Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 2, 2017, 11:15pm UTC](https://forum.ansible.com/t/use-fetch-module-with-wild-card-or-best-way-to-grab-different-name-file-from-several-hosts/25903/2 "2017-11-02T23:15:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kent\_Younge](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kent\_Younge](https://forum.ansible.com/u/Kent_Younge)\
**Post date:** [November 2, 2017, 11:30pm UTC](https://forum.ansible.com/t/use-fetch-module-with-wild-card-or-best-way-to-grab-different-name-file-from-several-hosts/25903/3 "2017-11-02T23:30:53Z")

</div>

So how would it look?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 3, 2017, 2:43am UTC](https://forum.ansible.com/t/use-fetch-module-with-wild-card-or-best-way-to-grab-different-name-file-from-several-hosts/25903/4 "2017-11-03T02:43:04Z")

</div>

this explains it.  
[http://docs.ansible.com/ansible/latest/playbooks\_variables.html#registered-variables](http://docs.ansible.com/ansible/latest/playbooks_variables.html#registered-variables)

---

<div class="post-metadata">

**Author:** ![Kent\_Younge](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kent\_Younge](https://forum.ansible.com/u/Kent_Younge)\
**Post date:** [November 3, 2017, 12:40pm UTC](https://forum.ansible.com/t/use-fetch-module-with-wild-card-or-best-way-to-grab-different-name-file-from-several-hosts/25903/5 "2017-11-03T12:40:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kent\_Younge](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kent\_Younge](https://forum.ansible.com/u/Kent_Younge)\
**Post date:** [November 3, 2017, 4:10pm UTC](https://forum.ansible.com/t/use-fetch-module-with-wild-card-or-best-way-to-grab-different-name-file-from-several-hosts/25903/6 "2017-11-03T16:10:03Z")

</div>

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.
