Copy files from windows machine to linux machine using ansible

4,505 views
Skip to first unread message

Mick st john

unread,
Apr 25, 2016, 10:06:04 AM4/25/16
to Ansible Project
I trying to copy files from a remote windows machine to my local machine(linux machine) using ansible. As fetch module works for linux to linux file transfer, is there anything similar that could enable me to fetch files from windows machine to linux machine?

J Hawkesworth

unread,
Apr 25, 2016, 10:54:58 AM4/25/16
to Ansible Project
Fetch can also fetch from windows machines back to your ansible controller machine.

If you are fetching from > 1 windows box don't forget to fetch to a directory, or use something like {{ inventory_hostname_short }} when generating the file name.

Hope this helps,

Jon

Mick st john

unread,
Apr 26, 2016, 12:04:12 AM4/26/16
to Ansible Project
I tried the following playbook:

---
- hosts: windows
  tasks:
     - name: copy file
       fetch: src=\path\to\file\on\windows\machine dest=/destination/directory

But, somehow it failed. Am I doing it the wrong way?

Mick st john

unread,
Apr 26, 2016, 12:13:06 AM4/26/16
to Ansible Project
I did some changes and it worked. But, the whole directory is getting created on the linux machine which has the desired file.

Mick st john

unread,
Apr 26, 2016, 12:35:18 AM4/26/16
to Ansible Project
 I used flat=yes and the issue is now resolved. Thank you!

Vigneshwar V

unread,
Nov 9, 2016, 8:25:34 AM11/9/16
to Ansible Project
Can you tell me what are the changes you made

J Hawkesworth

unread,
Nov 9, 2016, 12:44:14 PM11/9/16
to Ansible Project
This ought to do it (not tested).

Jon

---
- hosts: windows
  tasks:
     - name: copy file back to ansible machine from windows
       fetch:
          src: \path\to\file\on\windows\machine
          dest: /destination/directory/on/ansible/controller
          flat: yes
       delegate_to: a_windows_host

Ricky V.

unread,
Mar 13, 2018, 9:50:53 PM3/13/18
to Ansible Project
But this won't run and there's no error,


--- 
- hosts: windows
  tasks:
     - name: copy file back to ansible machine from windows
       fetch: 
          src: \path\to\file\on\windows\machine
          dest: /destination/directory/on/ansible/controller
          flat: yes
       delegate_to: ansible_hostname

Any idea if you want to get the data from multiple windows server?

Jordan Borean

unread,
Mar 14, 2018, 4:39:38 PM3/14/18
to Ansible Project
If you can share the error we may be able to help, my thoughts are the delegate_to isn't needed and the src path is inavlid but without any more info we can't really help.
Reply all
Reply to author
Forward
0 new messages