我正在尝试使用“ anisble”程序而不是在剧本中将win_shell Ansible模块作为临时命令运行。这是剧本的语法:
tasks:
- win_shell: foo.exe
args:
chdir: 'C:\bar'
executable: cmd
我尝试了各种排列,例如:
ansible \* -i windows.inventory -k -m win_shell -a "foo" -a "executable=cmd"
ansible \* -i windows.inventory -k -m win_shell -a "foo" -a "args: executable=cmd"
ansible \* -i windows.inventory -k -m win_shell -a "foo" -a "args=executable: cmd"
ansible \* -i windows.inventory -k -m win_shell -a "foo" -a "args=(executable=cmd)"
ansible \* -i windows.inventory -k -m win_shell -a "foo" -a "args={{arg}}" -e '{arg: {executable: cmd} {chdir: "C:\\bar"}}'
ansible \* -i windows.inventory -k -m win_shell -a "foo" -a "args={{arg}}" -e '{arg: {executable: cmd},{chdir: "C:\\bar"}}'
ansible \* -i windows.inventory -k -m win_shell -a "foo" -a "args={{arg}}" -e '{"arg": {"executable": "cmd"},{"chdir": "C:\\bar"}}'
ansible \* -i windows.inventory -k -m win_shell -a "foo" -a "args={{arg}}" -e '{"arg": {"executable": "cmd"},{"chdir": "C:\\bar"}}'
ansible \* -i windows.inventory -k -m win_shell -a "foo" -a "args={{arg}}" -e '{"arg": {"executable": "cmd"}}'
这些工作都没有。
我可以这样:
ansible \* -i windows.inventory -k -m win_shell -a 'cmd /c "cd C:\bar & foo"'
...但是我想知道如何通过指定“ args”来做到这一点。
答案 0 :(得分:1)
您应该使用Ansible内联语法和单个-a
参数,且不要拆分。
以下是任务转换为CLI参数的方式:
ansible \* -i windows.inventory -k -m win_shell -a 'foo.exe chdir=C:\bar executable=cmd'