我试图从特定组中获取特定变量,但这似乎导致我得到奇怪的结果。
主机文件示例:
[server_machine]
zeus account=app1
[agent_machine]
machine1 account=agent port_a=1000 port_b=1001
machine2 account=agent port_a=1200 port_b=1201
machine3 account=agent port_a=1300 port_b=1301
Run Code Online (Sandbox Code Playgroud)
我想做的是server_machine使用从组中获得的参数在组上运行脚本agent_machines。
这样,脚本将在server_machine所有端口组合上运行 3 次。
所以基本上我需要的剧本可能如下所示:
- hosts: server_machine
- tasks:
- command: test.py --port_1 {{item}} --port_2 {{item}}
with_items:{{group.agent_machine.port_a, group.agent_machine.port_b }}
Run Code Online (Sandbox Code Playgroud)
但是,我无法让它发挥作用。
尝试这个:
- command: test.py --port_1 {{ hostvars[item]["port_a"] }} --port_2 {{ hostvars[item]["port_b"] }}
with_items: groups["agent_machine"]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1908 次 |
| 最近记录: |