die*_*gus 3 windows fetch ansible
我想通过ansible获取在windows节点上创建的文件(info.txt)。我尝试使用 fetch 模块(它在 linux 节点上对我有用),它似乎不适用于 Windows 客户端。这是相关的代码:
task:
-name: Fetch a info file
fetch: src=C:\info.txt dest=/home/user flat=yes
Run Code Online (Sandbox Code Playgroud)
我没有收到错误,但未获取文件。我在本地机器上运行 ubuntu。难道我做错了什么?谢谢
这是使用 -vvv 选项运行的 playbook 的输出:
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"
Run Code Online (Sandbox Code Playgroud)
更改:[win1] => {“更改”:真,“校验和”:空,“dest”:“/home/diego/work/ansible_win/ex1”,“调用”:{“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}
它使用以下代码对我有用:
task:
- name: Fetch a info file
fetch: src=C:/info.txt dest=/home/user/info.txt flat=yes
Run Code Online (Sandbox Code Playgroud)
与之前的代码相比,我将“windows”反斜杠更改为斜杠,并在dest
路径末尾添加了文件名。