Jordan,

The solutions you've provided worked out fine.  I ended up using *win_shell* 
module simply because I was not able to pass *%computername%* variable in 
win_find patterns. I'm a beginner and ready to tackle regex :-)

I really appreciate your help. Also, by any chance the values in 
results.stdout_lines can be used in combication with the archive module to 
tar the files in result?

Thanks in advance.


















*- hosts: all  gather_facts: yes  tasks:   - win_shell: dir /b 
C:\Temp\*%computername%*     args:        executable: cmd     register: 
results   - debug:       var: results.stdout_lines   - name: get the 
files     fetch:       src: "C:/Temp/{{ item }}"       dest: 
/home/vagrant/win-script-result/       flat: yes     with_items: "{{ 
results.stdout_lines }}"*

On Wednesday, October 11, 2017 at 9:13:28 PM UTC-4, Jordan Borean wrote:
>
> Your indent for with_items is incorrect, it should be set on the task 
> level and not module level, so
>
> - name: get the files
>   fetch:
>     src: "C:/Temp/{{ item }}"
>     dest: /home/vagrant/win-script-result/
>     flat: yes
>   with_items: "{{ results.stdout_lines }}"
>
> I would also highly recommend swapping over to the win_find module instead 
> of running that command. It gives you more control over what to find as you 
> can add multiple regex strings to search and gives you room to expand in 
> the future. This is what it would look like;
>
> - name: find tar files
>   win_find:
>     paths: C:\temp
>     file_type: file
>     patterns: '*.tar'
>   register: tar_files
>
>
> - name: fetch tar files
>   fetch:
>     src: '{{ item.path }}'
>     dest: /home/vagrant/win-script-result/
>     flat: yes
>   with_items: '{{ tar_files.files }}'
>
> Both paths and patterns can take in a list so you can specify multiple 
> paths and patterns instead of running separate tasks. It also gives you the 
> ability to use regex if you really feel like hurting yourself :)
>
> Thanks
>
> Jordan
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20cb9d94-29d3-4a03-a064-d50b7ad065ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to