如何使用 Ansible 从 windows 节点获取文件
How to fetch a file from a windows node with Ansible
我想通过 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 选项:
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] => {"changed":真,"checksum":空,"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":空,"remote_checksum":“9664e0d22d3e184eb206d60af29e340f620092d0”,"remote_md5sum":空}
它适用于我的以下代码:
task:
- name: Fetch a info file
fetch: src=C:/info.txt dest=/home/user/info.txt flat=yes
与之前的代码相比,我已将 "windows" 反斜杠更改为斜杠,并在 dest
路径末尾添加了文件名。
我想通过 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 选项:
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] => {"changed":真,"checksum":空,"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":空,"remote_checksum":“9664e0d22d3e184eb206d60af29e340f620092d0”,"remote_md5sum":空}
它适用于我的以下代码:
task:
- name: Fetch a info file
fetch: src=C:/info.txt dest=/home/user/info.txt flat=yes
与之前的代码相比,我已将 "windows" 反斜杠更改为斜杠,并在 dest
路径末尾添加了文件名。