我需要创建C:\MSI文件夹以放置msi文件。这是我的任务:
tasks:
- name: Copy *.msi files from ./MSI to C:\MSI
file: path=C:\MSI state=directory
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误:
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."}
Run Code Online (Sandbox Code Playgroud)
在详细模式下,我看到由于某种原因,文件模块放入/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
...
Run Code Online (Sandbox Code Playgroud)
Ansible寻找/usr/bin/python该file模块,因为该模块需要在目标系统上安装Python。Windows目标无法使用正常的 Ansible模块。
请参阅Ansible Windows文档以获取详细信息。在Windows主机上,仅Ansible模块索引的“ windows”子类别中列出的模块可用。
要更换常规file模块,请使用该win_file模块。