【发布时间】:2020-08-04 15:43:19
【问题描述】:
如何在 ansible with loop 中获得相同的结果?
我想用
- debug:
msg: "{{ item.0 }} {{ item.1 }}"
loop: "{{ gs_hostname | product(wl_hostname) | list }}"
但我明白了:
好的:[本地主机] => { “味精”:{ “gs-01”:“wl-01”, "gs-02": "wl-02", “gs-03”:空, “gs-04”:空 } }
我的期望:
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
【问题讨论】:
标签: python loops ansible cycle