I'm trying to convert list of dicts with keys ip and port into list of list where values will be concatenated values ip:port. I have list of dicts in Ansible:
"updated_pool_members_list": [
[
{
"ip": "10.99.99.99",
"port": 80
},
{
"ip": "10.99.99.100",
"port": 80
},
{
"ip": "10.99.99.101",
"port": 80
}
],
[
{
"ip": "10.98.98.99",
"port": 80
},
{
"ip": "10.98.98.100",
"port": 80
}
]
]
What I want to get this:
[
"10.99.99.99:80",
"10.99.99.100:80",
"10.99.99.101:80"
],
[
"10.98.98.99:80",
"10.98.98.100:80"
]
Tried to make two separate lists of IPs and Ports:
- name: Get ip and port into lists
ansible.builtin.set_fact:
pool_ip_list: "{{ pool_ip_list + [pool_item | map(attribute='ip') ] }}"
pool_port_list: "{{ pool_port_list + [pool_item | map(attribute='port') ] }}"
loop: "{{ updated_pool_members_list }}"
loop_control:
loop_var: pool_item
Got
"pool_ip_list": [
[
"10.99.99.99",
"10.99.99.100",
"10.99.99.101"
],
[
"10.98.98.99",
"10.98.98.100"
]
]
and
"pool_port_list": [
[
80,
80,
80
],
[
80,
80
]
]
But stuck on concatenating items in list of lists. Maybe there is a better way how to achieve needed result ?