Ansible nested Dictionary parsing

vicks
Mon, 27 Nov 2023 16:36:56 +0000
Get Help

How to Parse deeply nested dictionary in Ansible to get key / value pair that is all nested inside ?

My dictionary output:

parser_output": {
“changed”: false,
“failed”: false,
“parsed”: {
“isis”: {
“2”: {
“vrf”: {
“default”: {
“interfaces”: {
“FH0/0/0/0”: {
“neighbors”: {
“B6”: {
“holdtime”: “24”,
“ietf_nsf”: “Unable”,
“snpa”: “PtoP”,
“state”: “Up”,
“type”: “L1”
}
}
},
“FH0/0/0/1”: {
“neighbors”: {
“BF0”: {
“holdtime”: “28”,
“ietf_nsf”: “Capable”,
“snpa”: “PtoP”,
“state”: “Up”,
“type”: “L1”
}
}
},
“FH0/0/0/2”: {
“neighbors”: {
“B8”: {
“holdtime”: “28”,
“ietf_nsf”: “Capable”,
“snpa”: “PtoP”,
“state”: “Up”,
“type”: “L1”
}
}
},
“FH0/1/0/1”: {
“neighbors”: {
“BF1”: {
“holdtime”: “25”,
“ietf_nsf”: “Capable”,
“snpa”: “PtoP”,
“state”: “Up”,
“type”: “L1”
}
}
},
“FH0/1/0/2”: {
“neighbors”: {
“B8”: {
“holdtime”: “22”,
“ietf_nsf”: “Capable”,
“snpa”: “PtoP”,
“state”: “Up”,
“type”: “L1”
}
}
},
“HundredGigE0/0/0/23/0”: {
“neighbors”: {
“BU0”: {
“holdtime”: “22”,
“ietf_nsf”: “Capable”,
“snpa”: “PtoP”,
“state”: “Up”,
“type”: “L1”
}
}
},
“HundredGigE0/1/0/23/0”: {
“neighbors”: {
“BU1”: {
“holdtime”: “20”,
“ietf_nsf”: “Capable”,
“snpa”: “PtoP”,
“state”: “Up”,
“type”: “L1”
}
}
}
},
“total_neighbor_count”: 7
}
}
}
}
},

My Code:

name: Print neighbors output
debug:
msg:
- Key: “{{ items.key }}”
- value: “{{ items.value }}”
loop: “{{ parser_output | subelements() }}”

Trying to use subelements how doesnt seem to work.
Any help here ?

3 posts - 3 participants