Ansible 循环浏览两个提取值中的列表
我有一个剧本,可以从网络设备中获取值,并为它们创建一个事实,数据如下所示Ansible 循环浏览两个提取值中的列表,ansible,Ansible,我有一个剧本,可以从网络设备中获取值,并为它们创建一个事实,数据如下所示 "response": [ { "address": "5555.6666.7777.8888", "age": "0", "interface": "Vlan4050, Ethernet23", "mac": "324c.23d7.7235" }, {
"response": [
{
"address": "5555.6666.7777.8888",
"age": "0",
"interface": "Vlan4050, Ethernet23",
"mac": "324c.23d7.7235"
},
{
"address": "111.222.333.444",
"age": "0",
"interface": "Vlan4051, Ethernet24",
"mac": "63g.aed6.892d"
}
]
我创建一个事实来获取每个对象的地址
- name: set list of addresses
set_fact:
address: "{{ arp_arista.response | map(attribute='address') | list }}"
然后我想调试每个地址的消息
- name: debug test
debug:
msg: "This is the IP: {{ item }}"
loop:
- "{{ address }}"
我希望这能产生效果
This is the IP: 5555.6666.7777.8888
This is the IP: 111.222.333.444
但相反,它输出
This is the IP: [u'5555.6666.7777.8888', u'111.222.333.444']
是否有一种方法可以分别循环和打印每个要使用的地址
问:“有没有一种方法可以分别循环和打印要使用的每个地址?”
A:是的。迭代列表中的项目地址
loop: "{{ address }}"
问题的解释 问题中的循环迭代一个项的显式列表,该项是列表
地址本身
loop:
- "{{ address }}"