I have the following list of dictionaries
"tor_vlan_list": [
{
"switch_01": {
"Vlan1": {
"id": "1",
"ip": "unassigned",
"ok": "NO",
"protocol": "down",
"status": "up"
},
"Vlan10": {
"id": "10",
"ip": "10.10.10.2/24",
"ok": "YES",
"protocol": "up",
"status": "up"
},
"Vlan20": {
"id": "20",
"ip": "10.10.20.2/24",
"ok": "YES",
"protocol": "up",
"status": "up"
},
"Vlan30": {
"id": "30",
"ip": "10.10.30.2/24",
"ok": "YES",
"protocol": "up",
"status": "up"
}
}
},
{
"switch_02": {
"Vlan1": {
"id": "1",
"ip": "unassigned",
"ok": "NO",
"protocol": "down",
"status": "up"
},
"Vlan10": {
"id": "10",
"ip": "10.10.10.3/24",
"ok": "YES",
"protocol": "up",
"status": "up"
},
"Vlan20": {
"id": "20",
"ip": "10.10.20.3/24",
"ok": "YES",
"protocol": "up",
"status": "up"
},
"Vlan30": {
"id": "30",
"ip": "10.10.30.3/24",
"ok": "YES",
"protocol": "up",
"status": "up"
}
}
}
]
from this, i need to extract the list of vlan IDs for each switch and store these as follows
"new_list": [
{
"switch_01": [1,10,20,30]
},
{
"switch_02": [1,10,20,30]
}
]
I would like to pass the list values as a var in the command *show vlan {{item}}"
I've tried getting the needed detail using combinations of selectattr, map, combine, json_query, etc to set a new ansible fact but, all have eluded me.
The below expressions
give what you want
Example of a complete playbook for testing