Ansible win_shell临时语法

时间:2018-10-12 16:48:50

标签: windows ansible yaml jinja2

我正在尝试使用“ 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”来做到这一点。

1 个答案:

答案 0 :(得分:1)

您应该使用Ansible内联语法和单个-a参数,且不要拆分。

以下是任务转换为CLI参数的方式:

ansible \* -i windows.inventory -k -m win_shell -a 'foo.exe chdir=C:\bar executable=cmd'