# Looping over JSON output from Arista

**URL:** <https://forum.ansible.com/t/looping-over-json-output-from-arista/16808>\
**Category:** Ansible Project\
**Created:** [November 17, 2014, 9:57pm UTC](https://forum.ansible.com/t/looping-over-json-output-from-arista/16808 "2014-11-17T21:57:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leo\_Izbicki](https://avatars.discourse-cdn.com/v4/letter/l/fbc32d/32.png) [@Leo\_Izbicki](https://forum.ansible.com/u/Leo_Izbicki)\
**Post date:** [November 17, 2014, 9:57pm UTC](https://forum.ansible.com/t/looping-over-json-output-from-arista/16808/1 "2014-11-17T21:57:42Z")

</div>

I’m playing with Ansible+Arista and I’m able to receive JSON back about the arista device. As an example, I am looking at interface status. While I am able to receive and display information about a single value/pair from the array, how can I loop to receive information on every item in the array?

Example JSON received:

TASK: [debug var=eos\_command\_output] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [example.host] =\> {  
“eos\_command\_output”: {  
“changed”: false,  
“invocation”: {  
“module\_args”: “”,  
“module\_name”: “eos\_command”  
},  
“output”: [  
{  
“command”: “show interfaces status”,  
“response”: {  
“interfaceStatuses”: {  
“Ethernet1”: {  
“autoNegotiateActive”: false,  
“autoNegotigateActive”: false,  
“bandwidth”: 10000000000,  
“description”: “example.description|span”,  
“duplex”: “duplexFull”,  
“interfaceType”: “10GBASE-SR”,  
“linkStatus”: “connected”,  
“vlanInformation”: {  
“interfaceForwardingModel”: “bridged”,  
“interfaceMode”: “tap”  
}  
},  
“Ethernet10”: {  
“autoNegotiateActive”: false,  
“autoNegotigateActive”: false,  
“bandwidth”: 10000000000,  
“description”: “”,  
“duplex”: “duplexFull”,  
“interfaceType”: “Not Present”,  
“linkStatus”: “errdisabled”,  
“vlanInformation”: {  
“interfaceForwardingModel”: “bridged”,  
“interfaceMode”: “bridged”,  
“vlanId”: 1  
}

Working example:

- name: show the optic in Ethernet1  
debug: msg=“Optic in Ethernet1- {{eos\_command\_output[‘output’][0][‘respons  
e’][‘interfaceStatuses’][‘Ethernet1’][‘interfaceType’] }}”

yields:

> ok: [example.host1] =\> {
> 
> “msg”: “Optic in Ethernet1- Not Present”
> 
> }
> 
> ok: [example.host2] =\> {
> 
> “msg”: “Optic in Ethernet1- 10GBASE-SR”

What I’m trying to do:

> - name: show the optic in each port
> 
> debug: msg="Optic in {{ eos\_command\_output[‘output’][0]['respons
> 
> e’][‘interfaceStatuses’] }} - {{ interfaceType }}

This doesn’t work, and so here I am.

Desired output:

> ok: [example.host1] =\> {
> 
> “msg”: “Optic in Ethernet1- Not Present”
> 
> “msg”: “Optic in Ethernet10- Not Present”
> 
> }
> 
> ok: [example.host2] =\> {
> 
> “msg”: “Optic in Ethernet1- 10GBASE-SR”
> 
> “msg”: “Optic in Ethernet10- Not Present”

Thanks!

Leo
