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
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/f5f7cb01-7f57-4c64-9a9e-0861a65a4723%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.