Loops 如何使用嵌套在2个dict上的_来获取ansible中的值?
我有以下两个地图设置Loops 如何使用嵌套在2个dict上的_来获取ansible中的值?,loops,dictionary,ansible,Loops,Dictionary,Ansible,我有以下两个地图设置 prefix_color: eu_: "blue" us_: "red" country_shade: sweden: "light" belgium: "dark" 我想用ansible中嵌套的以同样的方式循环两个映射,但我需要访问两个dict中的键和值 基本上我需要的是这样的东西 - name: loop debug: msg: "key: {{ item[0].key + item[1].key }}, value: {{ item[0
prefix_color:
eu_: "blue"
us_: "red"
country_shade:
sweden: "light"
belgium: "dark"
我想用ansible中嵌套的以同样的方式循环两个映射,但我需要访问两个dict中的键和值
基本上我需要的是这样的东西
- name: loop
debug:
msg: "key: {{ item[0].key + item[1].key }}, value: {{ item[0].value + item[1].value }}"
with_nested:
- "{{ prefix_color }}"
- "{{ country_shade }}"
上述操作不起作用,因为只有使用嵌套的和的键可用,并且使用dict的不允许使用超过一个字典
这件事怎么办?鉴于ansible中同时存在嵌套循环和字典的概念,这似乎应该是一件简单的事情。您可以使用它将字典转换为列表:
- name: loop
debug:
msg: "key: {{ item[0] + item[2] }}, value: {{ item[1] + item[3] }}"
with_nested:
- "{{ prefix_color | dictsort }}"
- "{{ country_shade | dictsort }}"
在您的设置中,原始关键点的索引将为偶数,而值将为不均匀。谢谢。但我认为这是Ansible中缺少的东西,应该得到适当的解决