我在 ansible 中每个主机有两个词典:
{ “rtt”:[38,1,97] }
{ “站点”:[“A”,“B”,“C”] }
我现在想要循环列表或项目,其中我可以引用各个项目,例如:
debug:
msg: "{{ item.site }} is {{ item.rtt }}"
with_items: "{{ X }}"
我如何构造 X?
答案1
这大概就是你在寻找的东西吧?
- hosts: localhost
vars:
rtt: [38,1,97]
site: ["A","B","C"]
tasks:
- debug:
msg: "{{ item.0 }} is {{ item.1 }}"
loop: "{{ site|zip(rtt)|list }}"
给出
msg: A is 38
msg: B is 1
msg: C is 97