Ansible with Windows node - 如何创建目录

时间:2016-10-25 16:33:02

标签: windows ansible

我需要创建C:\MSI文件夹来放置msi文件。这是我的任务:

tasks:
  - name: Copy *.msi files from ./MSI to C:\MSI
    file: path=C:\MSI state=directory

但是我得到了错误:

TASK [Copy *.msi files from ./MSI to C:\MSI] ***********************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: + ~~~~~~~~~~~~~~~
fatal: [agentsmith]: FAILED! => {"changed": false, "failed": true, "msg": "The term '/usr/bin/python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."}

并且在详细模式下,我看到文件模块由于某种原因将/usr/bin/python放到Powershell脚本中:

TASK [Copy *.msi files from ./MSI to C:\MSI] ***********************************
task path: /home/qaexpert/ansible-lab/tcagent.yml:8
<agentsmith> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO agentsmith
<agentsmith> EXEC Set-StrictMode -Version Latest
(New-Item -Type Directory -Path $env:temp -Name "ansible-tmp-1477410445.62-187863101456896").FullName | Write-Host -Separator '';
<agentsmith> PUT "/tmp/tmpqOJYen" TO "C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1477410445.62-187863101456896\file.ps1"
<agentsmith> EXEC Set-StrictMode -Version Latest
Try
{
/usr/bin/python 'C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1477410445.62-187863101456896\file.ps1'
}
Catch
...

1 个答案:

答案 0 :(得分:4)

Ansible会查找/usr/bin/python,因为file模块需要在目标系统上安装Python。对于Windows目标,无法使用普通 Ansible模块。

查看Ansible Windows documentation了解详情。在Windows主机上,只有“windows” subcategory of the Ansible module index中列出的模块可用。

要替换常规file模块,请使用win_file模块。