【发布时间】:2016-02-17 16:43:37
【问题描述】:
我想通过ansible获取一个在windows节点上创建的文件(info.txt)。我尝试使用 fetch 模块(在 linux 节点上适用于我),它似乎不适用于 Windows 客户端。以下是相关代码:
task:
-name: Fetch a info file
fetch: src=C:\info.txt dest=/home/user flat=yes
我没有收到错误,但未获取文件。我在本地机器上运行 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"
更改:[win1] => {“更改”:true,“校验和”:null,“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}
【问题讨论】:
-
我认为您需要将您的
src反斜杠更改为正斜杠,例如C:/info.txt. -
试过了,没什么区别..
-
什么版本的ansible?
-
您能否在运行 playbook 时添加
-vvv开关并将日志输出粘贴到您的问题中? -
嗯....我正在运行 1.9.4,但行为相同。看起来它已经复制了文件,但在我的主目录中没有任何内容:/