diegus
diegus

Reputation: 1188

How to fetch a file from a windows node with Ansible

I would like to fetch a file (info.txt) that has been created on a windows node through ansible. I have tried to use the fetch module (which works for me on a linux node), which seems not to work on a windows client. Here is the relevant code:

task:
  -name: Fetch a info file
   fetch: src=C:\info.txt dest=/home/user flat=yes 

I get no error but the file is not fetched. I run ubuntu on my local machine. Am I doing something wrong? thanks

Here is the output of the playbook run with -vvv option on:

If (Test-Path -PathType Leaf "C:\info.txt")
{
$sp = new-object -TypeName   System.Security.Cryptography.SHA1CryptoServiceProvider;
$fp = [System.IO.File]::Open("C:\info.txt[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read);
[System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower();
$fp.Dispose();
}
ElseIf (Test-Path -PathType Container "C:\info.txt")
{
Write-Host "3";
}
Else 
{
Write-Host "1";
} 
<192.168.122.123> FETCH "C:\info.txt" TO "/home/diego/work/ansible_win/ex1"

changed: [win1] => {"changed": true, "checksum": null, "dest": "/home/diego/work/ansible_win/ex1", "invocation": {"module_args": {"dest": "/home/diego/work/ansible_win/ex1", "flat": "yes", "src": "C:/info.txt"}, "module_name": "fetch"}, "md5sum": null, "remote_checksum": "9664e0d22d3e184eb206d60af29e340f620092d0", "remote_md5sum": null}

Upvotes: 5

Views: 15068

Answers (1)

diegus
diegus

Reputation: 1188

It works for me with the following code:

task:
  - name: Fetch a info file
    fetch: src=C:/info.txt dest=/home/user/info.txt flat=yes 

Compare to the previous code I have changed the "windows" backslash into a slash and added the name of the file at the end of the dest path.

Upvotes: 11

Related Questions