# Debugging ACI query task

**URL:** <https://forum.ansible.com/t/debugging-aci-query-task/32508>\
**Category:** Ansible Project\
**Created:** [March 22, 2020, 6:10pm UTC](https://forum.ansible.com/t/debugging-aci-query-task/32508 "2020-03-22T18:10:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert\_Short](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Albert\_Short](https://forum.ansible.com/u/Albert_Short)\
**Post date:** [March 22, 2020, 6:10pm UTC](https://forum.ansible.com/t/debugging-aci-query-task/32508/1 "2020-03-22T18:10:57Z")

</div>

Hello all,

I hope we are all well in this trying period across the world.

I am to debug an ACI query to display a simple output, but having trouble getting the correct syntax to provide the output I desire.

My Ansible Script to query a BD & the debug script to **try** to display just the subnet information.

`

- name: ACI Subnet query allocated to BD  
hosts: apics  
gather\_facts: no

tasks:

- name: Query BD  
aci\_bd\_subnet:  
host: “{{ ansible\_host }}”  
username: “{{ ansible\_user }}”  
password: “{{ ansible\_password }}”  
validate\_certs: no  
tenant: tn\_TRAINER  
state: query  
register: subnet\_output

- name: Debug message for ACI  
debug:  
msg: “Subnet : {{subnet\_output.current}}”  
`

Now my output:  
`

$ ansible-playbook aci\_debug.yml

PLAY [ACI Subnet query allocated to BD] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Query BD] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [apic2]

TASK [Debug message for ACI] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [apic2] =\>  
msg: ‘Subnet : [{u’‘fvTenant’‘: {u’‘attributes’‘: {u’‘dn’‘: u’‘uni/tn-tn\_TRAINER’‘, u’‘lcOwn’‘: u’‘local’‘, u’‘ownerKey’‘: u’‘’‘, u’‘name’‘: u’‘tn\_TRAINER’‘, u’‘descr’‘: u’‘Trainer Tenant’‘, u’‘extMngdBy’‘: u’‘’‘, u’‘annotation’‘: u’‘’‘, u’‘status’‘: u’‘’‘, u’‘monPolDn’‘: u’‘uni/tn-common/monepg-default’‘, u’‘modTs’‘: u’‘2020-03-21T09:32:40.162+00:00’‘, u’‘ownerTag’‘: u’‘’‘, u’‘childAction’‘: u’‘’‘, u’‘nameAlias’‘: u’‘’‘, u’‘uid’‘: u’‘15374’‘}, u’‘children’‘: [{u’‘fvBD’‘: {u’‘attributes’‘: {u’‘uid’‘: u’‘15374’‘, u’‘extMngdBy’‘: u’‘’‘, u’‘arpFlood’‘: u’‘yes’‘, u’‘seg’‘: u’‘16482194’‘, u’‘mcastAllow’‘: u’‘no’‘, u’‘ipv6McastAllow’‘: u’‘no’‘, u’‘intersiteL2Stretch’‘: u’‘no’‘, u’‘unicastRoute’‘: u’‘yes’‘, u’‘unkMcastAct’‘: u’‘flood’‘, u’‘OptimizeWanBandwidth’‘: u’‘no’‘, u’‘v6unkMcastAct’‘: u’‘flood’‘, u’‘descr’‘: u’‘’‘, u’‘hostBasedRouting’‘: u’‘no’‘, u’‘llAddr’‘: u’‘::’‘, u’‘monPolDn’‘: u’‘uni/tn-common/monepg-default’‘, u’‘modTs’‘: u’‘2020-03-22T17:41:28.775+00:00’‘, u’‘scope’‘: u’‘2228224’‘,  
u’‘rn’‘: u’‘BD-bd\_VLAN101’‘, u’‘type’‘: u’‘regular’‘, u’‘ipLearning’‘: u’‘yes’‘, u’‘status’‘: u’‘’‘, u’‘vmac’‘: u’‘not-applicable’‘, u’‘nameAlias’‘: u’‘’‘, u’‘configIssues’‘: u’‘’‘, u’‘bcastP’‘: u’‘225.1.27.48’‘, u’‘mac’‘: u’‘00:22:BD:F8:19:FF’‘, u’‘epMoveDetectMode’‘: u’‘’‘, u’‘ownerTag’‘: u’‘’‘, u’‘intersiteBumTrafficAllow’‘: u’‘no’‘, u’‘annotation’‘: u’‘’‘, u’‘childAction’‘: u’‘’‘, u’‘lcOwn’‘: u’‘local’‘, u’‘ownerKey’‘: u’‘’‘, u’‘name’‘: u’‘bd\_VLAN101’‘, u’‘epClear’‘: u’‘no’‘, u’‘unkMacUcastAct’‘: u’‘proxy’‘, u’‘multiDstPktAct’‘: u’‘bd-flood’‘, u’‘limitIpLearnToSubnets’‘: u’‘yes’‘, u’‘mtu’‘: u’‘inherit’‘, u’‘pcTag’‘: u’‘32771’‘}, u’‘children’‘: [{u’‘fvSubnet’‘: {u’‘attributes’‘: {u’‘status’‘: u’‘’‘, u’‘lcOwn’‘: u’‘local’‘, u’‘uid’‘: u’‘15374’‘, u’‘descr’‘: u’‘’‘, u’‘extMngdBy’‘: u’‘’‘, u’‘ip’‘: u’‘192.168.101.1/24’‘, u’‘ctrl’‘: u’‘’‘, u’‘preferred’‘: u’‘no’‘, u’‘name’‘: u’‘’‘, u’‘virtual’‘: u’‘no’‘, u’‘nameAlias’‘: u’‘’‘, u’‘scope’‘: u’‘private’‘, u’‘monPolDn’‘: u’‘uni/tn-common/monepg-default’‘,  
u’‘rn’‘: u’‘subnet-[192.168.101.1/24]’‘, u’‘modTs’‘: u’‘2020-03-22T17:41:28.723+00:00’‘, u’‘annotation’‘: u’‘’‘, u’‘childAction’‘: u’‘’‘}}}]}}]}}]’

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
apic2 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0  
`

The verbose output for the ‘Query BD’ task looks as follows:

`  
TASK [Query BD] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [apic2] =\> changed=false  
ansible\_facts:  
discovered\_interpreter\_python: /usr/bin/python  
current:

- fvTenant:  
attributes:  
annotation: ‘’  
childAction: ‘’  
descr: Trainer Tenant  
dn: uni/tn-tn\_TRAINER  
extMngdBy: ‘’  
lcOwn: local  
modTs: ‘2020-03-21T09:32:40.162+00:00’  
monPolDn: uni/tn-common/monepg-default  
name: tn\_TRAINER  
nameAlias: ‘’  
ownerKey: ‘’  
ownerTag: ‘’  
status: ‘’  
uid: ‘15374’  
children:
- fvBD:  
attributes:  
OptimizeWanBandwidth: ‘no’  
annotation: ‘’  
arpFlood: ‘yes’  
bcastP: 225.1.27.48  
childAction: ‘’  
configIssues: ‘’  
descr: ‘’  
epClear: ‘no’  
epMoveDetectMode: ‘’  
extMngdBy: ‘’  
hostBasedRouting: ‘no’  
intersiteBumTrafficAllow: ‘no’  
intersiteL2Stretch: ‘no’  
ipLearning: ‘yes’  
ipv6McastAllow: ‘no’  
lcOwn: local  
limitIpLearnToSubnets: ‘yes’  
llAddr: ‘::’  
mac: 00:22:BD:F8:19:FF  
mcastAllow: ‘no’  
modTs: ‘2020-03-22T17:41:28.775+00:00’  
monPolDn: uni/tn-common/monepg-default  
mtu: inherit  
multiDstPktAct: bd-flood  
name: bd\_VLAN101  
nameAlias: ‘’  
ownerKey: ‘’  
ownerTag: ‘’  
pcTag: ‘32771’  
rn: BD-bd\_VLAN101  
scope: ‘2228224’  
seg: ‘16482194’  
status: ‘’  
type: regular  
uid: ‘15374’  
unicastRoute: ‘yes’  
unkMacUcastAct: proxy  
unkMcastAct: flood  
v6unkMcastAct: flood  
vmac: not-applicable  
children:
- fvSubnet:  
attributes:  
annotation: ‘’  
childAction: ‘’  
ctrl: ‘’  
descr: ‘’  
extMngdBy: ‘’  
ip: 192.168.101.1/24  
lcOwn: local  
modTs: ‘2020-03-22T17:41:28.723+00:00’  
monPolDn: uni/tn-common/monepg-default  
name: ‘’  
nameAlias: ‘’  
preferred: ‘no’  
rn: subnet-[192.168.101.1/24]  
scope: private  
status: ‘’  
uid: ‘15374’  
virtual: ‘no’

`

I am trying to get a debug message similar to:  
msg: ‘Subnet : 192.168.101.1/24’  
But I can’t work out how to do that from the registered output  
I have tried:  
`

- name: Debug message for ACI  
debug:  
msg: “Subnet : {{subnet\_output.current.fvTenant}}”  
`

But get this meesage:

`  
$ ansible-playbook aci\_debug.yml

PLAY [ACI Subnet query allocated to BD] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\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*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [apic2]: FAILED! =\>  
msg: |-  
The task includes an option with an undefined variable. The error was: ‘list object’ has no attribute ‘fvTenant’

The error appears to be in ‘/home/network\_automation/trainer/aci\_debug.yml’: line 21, column 7, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Debug message for ACI  
^ here

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
apic2 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

`

I have tried to find an answer but not managed to get a solution. Anyone got some guidance?

Thanks & be safe

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 22, 2020, 8:09pm UTC](https://forum.ansible.com/t/debugging-aci-query-task/32508/2 "2020-03-22T20:09:55Z")

</div>

Hi

The error is pretty clear:

> fatal: [apic2]: FAILED! =\>  
> msg: |-  
> The task includes an option with an undefined variable. The error was: ‘list object’ has no attribute ‘fvTenant’
> 
> The error appears to be in ‘/home/network\_automation/trainer/aci\_debug.yml’: line 21, column 7, but may  
> be elsewhere in the file depending on the exact syntax problem.

Your variable is a list of one item, which itself is deeply nested.  
Try this:

- debug:  
msg: “Subnet: {{ current.0.fvTenant.children.0.fvBD.children.0.fvSubnet.attributes.ip }}”

this is the ‘ip’ key which has the value that you are looking for -  
not sure if this correct?

---

<div class="post-metadata">

**Author:** ![Albert\_Short](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Albert\_Short](https://forum.ansible.com/u/Albert_Short)\
**Post date:** [March 23, 2020, 5:36am UTC](https://forum.ansible.com/t/debugging-aci-query-task/32508/3 "2020-03-23T05:36:37Z")

</div>

Dick that worked perfectl!

My next question is how would I get the same response to for several subnets without having to use the ‘0’ in the debug message?

`

- name: Debug message for ACI  
debug:  
msg:
- “Subnet : {{subnet\_output.current.0.fvTenant.children.0.fvBD.children.0.fvSubnet.attributes.ip}}”
- “Subnet : {{subnet\_output.current.0.fvTenant.children.0.fvBD.children.1.fvSubnet.attributes.ip}}”
- “Subnet : {{subnet\_output.current.0.fvTenant.children.0.fvBD.children.2.fvSubnet.attributes.ip}}”  
`

Regards

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 23, 2020, 7:55am UTC](https://forum.ansible.com/t/debugging-aci-query-task/32508/4 "2020-03-23T07:55:12Z")

</div>

Hi

This is slightly more involved, you can use the json\_query filter, it has a little bit different syntax.  
If you are going to iterate over a number of those subnets, I suggest creating a dedicated variable for that.  
Something like this:

tasks:

- set\_fact:  
subnets: “{{ subnet\_output | json\_query(‘current[0].fvTenant.children[0].fvBD.children.fvSubnet.attributes.ip’) }}”

- debug: var=subnets

- debug:  
msg: “{% for subnet in subnets %}Subnet: {{ subnet }}\n{% endfor %}”

---

<div class="post-metadata">

**Author:** ![J111](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@J111](https://forum.ansible.com/u/J111)\
**Post date:** [March 23, 2020, 6:10pm UTC](https://forum.ansible.com/t/debugging-aci-query-task/32508/5 "2020-03-23T18:10:38Z")

</div>

Hi Albert,  
I got the following code:

```auto
tasks:
    - name: gather info on a subnet
      aci_bd_subnet:
        host: 192.168.1.100
        username: admin
        password: "{{password}}"
        tenant: AciTest5
        bd: bd-test5
        state: query
        validate_certs: no
      delegate_to: localhost
      register: results
    - name: print results
      debug:
        var: results.current[0].fvBD.children[0].fvSubnet.attributes.rn
~                                                                       

```

---

<div class="post-metadata">

**Author:** ![J111](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@J111](https://forum.ansible.com/u/J111)\
**Post date:** [March 23, 2020, 8:22pm UTC](https://forum.ansible.com/t/debugging-aci-query-task/32508/6 "2020-03-23T20:22:00Z")

</div>

This worked for me for a specific bridge domain that had multiple subnets.  
I created a loop to loop over the lists and map the subnet attribute.

The results looked like this

```auto
tasks:
    - name: gather info on a subnet
      aci_bd_subnet:
        host: 192.168.1.1
        username: admin
        password: "{{password}}"
        tenant: AciTest5
        bd: bd-test5
        state: query
        validate_certs: no
      delegate_to: localhost
      register: results
    - name: print results
      debug:
        msg: "{{item}}"
      **loop: "{{results.current[0].fvBD.children[:] | map(attribute='fvSubnet.attributes.rn') | list }}"**

```

```auto

```

```auto

```
