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

3,125 views
Skip to first unread message

Kent Younge

unread,
Nov 2, 2017, 1:42:31 PM11/2/17
to Ansible Project
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, 

Brian Coca

unread,
Nov 2, 2017, 7:15:45 PM11/2/17
to Ansible Project
fetch does not support wildcards, register the data from find and use
that in loop in fetch

--
----------
Brian Coca

Kent Younge

unread,
Nov 2, 2017, 7:31:08 PM11/2/17
to ansible...@googlegroups.com
So how would it look?
> --
> You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/Xzhzm-vXteY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7d5vsDry8PbMaLiOOoVXwiSkFrZak_SN3VOfxbvP3_qeQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Nov 2, 2017, 10:43:23 PM11/2/17
to Ansible Project

Kent Younge

unread,
Nov 3, 2017, 8:40:28 AM11/3/17
to Ansible Project
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.

Kent Younge

unread,
Nov 3, 2017, 12:10:03 PM11/3/17
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages