我有一个剧本,可以在远程Windows主机上上传文件,然后执行它。问题是我的路径中有空格,并且剧本在“执行文件”上失败。这是剧本:
- name: Copy file and run
hosts: terminals
tasks:
- name: Copy a single file
win_copy:
src: '/tmp/ASDTech Shell Terminal Setup 4.0.0.exe'
dest: 'C:\Temp\ASDTech Shell Terminal Setup 4.0.0.exe'
- name: Check if file exist
win_stat:
path: 'C:\Temp\ASDTech Shell Terminal Setup 4.0.0.exe'
register: file_info
- name: Execute file
raw: 'C:\Temp\ASDTech Shell Terminal Setup 4.0.0.exe'
when: file_info.stat.exists == True
错误是:
TASK [Execute file] *************************************************************************************************************************************************************************************************************************
fatal: [50.18.46.45]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 1, "stderr": "C:\\\\Temp\\\\ASDTech : The term 'C:\\\\Temp\\\\ASDTech' is not recognized as the name of a cmdlet, function, script file, or \r\noperable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try \r\nagain.\r\nAt line:1 char:1\r\n+ C:\\\\Temp\\\\ASDTech Shell Terminal Setup 4.0.0.exe\r\n+ ~~~~~~~~~~~~~~~~\r\n + CategoryInfo : ObjectNotFound: (C:\\\\Temp\\\\ASDTech:String) [], CommandNotFoundException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n ", "stderr_lines": ["C:\\\\Temp\\\\ASDTech : The term 'C:\\\\Temp\\\\ASDTech' 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.", "At line:1 char:1", "+ C:\\\\Temp\\\\ASDTech Shell Terminal Setup 4.0.0.exe", "+ ~~~~~~~~~~~~~~~~", " + CategoryInfo : ObjectNotFound: (C:\\\\Temp\\\\ASDTech:String) [], CommandNotFoundException", " + FullyQualifiedErrorId : CommandNotFoundException", " "], "stdout": "", "stdout_lines": []}
任何人都可以提示我,要使用哪个模块或如何重写“执行文件”任务,以正确处理带空格的路径。
答案 0 :(得分:1)
您有很多可以在Windows上使用的模块,
要执行某件事,您有win_shell
(可能由于环境问题而处于危险状态)win_command
。
可以在ansible-doc win_command
另请参阅本指南:
Using Ansible and Windows
有使用win_command
模块的示例,您会发现您不必烦恼空格。