I have this JSON in a variable :
{
"device_vlans": {
"1": {
"name": "default",
"interfaces": [
"GigabitEthernet1/1",
"GigabitEthernet1/2",
"GigabitEthernet1/3"
]
},
"20": {
"name": "VLAN20",
"interfaces": [
"GigabitEthernet1/2"
]
},
"30": {
"name": "VLAN30",
"interfaces": [
"GigabitEthernet1/3"
]
}
}
But I need it to look more like this :
{
"device_vlans": {
"GigabitEthernet1/1": {
"vlans": [
"1"
]
},
"GigabitEthernet1/2": {
"vlans": [
"1",
"20"
]
},
"GigabitEthernet1/3": {
"vlans": [
"1",
"30"
]
}
}
Currently I'm looping over all interfaces of the device and inside that loop I'm looping over all items in the device_vlans variable with a when: item == interface
. It's really slow and causing me problems..
Is there any better way of doing that with ansible ?
I thought of a custom filter would that be the solution ?