如何在ansible with loop中获得相同的结果
我想用
- debug:
msg: "{{ item.0 }} {{ item.1 }}"
loop: "{{ gs_hostname | product(wl_hostname) | list }}"
但我得到:
ok: [localhost] => { "msg": { "gs-01": "wl-01", "gs-02": "wl-02", "gs-03": null, "gs-04": null } }
我所期望的是:
from itertools import cycle
gs_hostname = ["gs01", "gs02", "gs03", "gs04"]
wl_hostname = ["wl01", "wl02"]
for a,b in zip(gs_hostname, cycle(wl_hostname)):
print (a,b)
结果:
gs01 wl01 gs02 wl02 gs03 wl01 gs04 wl02
看起来Ansible中并没有任何本机功能可以实现这一点
也就是说,为了实现这一点,您可以使用一点计算和一个modulo与循环^{} 耦合
根据剧本:
这将作为输出提供:
我找到了另一个解决方案:
更多信息here
相关问题 更多 >
编程相关推荐