首页 文章

如何使用Ansible从Windows节点获取文件

提问于
浏览
3

我想通过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,“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}

1 回答

  • 4

    它适用于我使用以下代码:

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

    与前面的代码相比,我将"windows"反斜杠更改为斜杠,并在 dest 路径末尾添加了文件名 .

相关问题