gpt4 book ai didi

windows - Ansible win_shell 临时语法

转载 作者:可可西里 更新时间:2023-11-01 09:32:15 25 4
gpt4 key购买 nike

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

最佳答案

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

以下是任务如何转换为 CLI 参数:

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

关于windows - Ansible win_shell 临时语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52783865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com