# Help Reading through nested output

**URL:** <https://forum.ansible.com/t/help-reading-through-nested-output/35354>\
**Category:** Ansible Project\
**Created:** [June 15, 2021, 6:45pm UTC](https://forum.ansible.com/t/help-reading-through-nested-output/35354 "2021-06-15T18:45:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Kellyman](https://avatars.discourse-cdn.com/v4/letter/n/51bf81/32.png) [@Nathan\_Kellyman](https://forum.ansible.com/u/Nathan_Kellyman)\
**Post date:** [June 15, 2021, 6:45pm UTC](https://forum.ansible.com/t/help-reading-through-nested-output/35354/1 "2021-06-15T18:45:59Z")

</div>

Hi, I’m new to ansible, and i’m seeking some help. i’m writing a playbook that should iterate through a group, gather facts, then check the relevant variables against a defined condition, then perform an action depending on whether the condition is met. However, for simple conditions like x == y, i can get that to work, but when the condition is a{b{c}} == y, i cant get that to work. i think my issue here is syntax, but i’m not sure. please see a cut out of my code below, and what i’m trying to do:

**This is the out put i’m trying to check the conditions against:**

“ansible\_net\_interfaces”: {  
“GigabitEthernet1”: {  
“bandwidth”: 1000000,  
“description”: null,  
“duplex”: “Auto”,  
“ipv4”: [  
{  
“address”: “192.168.100.14”,  
“subnet”: “24”  
}  
],  
“lineprotocol”: “up”,  
“macaddress”: “0050.568b.5110”,  
“mediatype”: “RJ45”,  
“mtu”: 1500,  
“operstatus”: “up”,  
“type”: “CSR vNIC”  
},

**This is my code:**

- hosts: cisco

vars:  
HOST\_COUNT: “{{ groups[‘cisco’] | length }}”

tasks:

- name: Check Status {{ item }}  
gather\_facts:  
register: ip\_brief

**#- name: Check against variable - this is where i’m stuck. i want to say:**  
**when: ansible\_net\_interfaces-GigabitEthernet1-ipv4-address == “192.168.100.14”**  
**#but i dont know how to express this**

- name: print  
debug:  
var: ip\_brief

with\_items:

- “{{ HOST\_COUNT }}”

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [June 15, 2021, 7:24pm UTC](https://forum.ansible.com/t/help-reading-through-nested-output/35354/2 "2021-06-15T19:24:49Z")

</div>

Get the list of the addresses. There might be more of them, e.g.

&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: ips  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ips: "{{ ansible\_net\_interfaces.GigabitEthernet1.ipv4|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map(attribute='address')|list }}

gives

&nbsp;&nbsp;ips:  
&nbsp;&nbsp;- 192.168.100.14

Then test the presence of the address in the list, e.g.

&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "[OK] 192.168.100.14"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: "'192.168.100.15' in ips"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ips: "{{ ansible\_net\_interfaces.GigabitEthernet1.ipv4|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map(attribute='address')|list }}"

gives

&nbsp;&nbsp;msg: '[OK] 192.168.100.14'

---

<div class="post-metadata">

**Author:** ![Nathan\_Kellyman](https://avatars.discourse-cdn.com/v4/letter/n/51bf81/32.png) [@Nathan\_Kellyman](https://forum.ansible.com/u/Nathan_Kellyman)\
**Post date:** [June 15, 2021, 7:48pm UTC](https://forum.ansible.com/t/help-reading-through-nested-output/35354/3 "2021-06-15T19:48:31Z")

</div>

Thank you! This is greatly appreciated, and expressed the syntax i needed.
