Hi Albert,
I got the following code:
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
~
On Sun, Mar 22, 2020 at 2:11 PM Albert Short <[email protected]> wrote:
> 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]' <http://192.168.101.1/24%5D'>',
> 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]
> ************************************************************************************************************************************************************************************************
>
> TASK [Query BD]
> ************************************************************************************************************************************************************************************************************************
> ok: [apic2]
>
> TASK [Debug message for ACI]
> ***********************************************************************************************************************************************************************************************************
> 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
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/1a14f8d3-1463-44d0-9e49-f36f1a1c22ac%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/1a14f8d3-1463-44d0-9e49-f36f1a1c22ac%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAFFkYJKPBdo-AZc0%3DiXD%3D5KrMnxC%3DiXztkfNDuTHXdf-1R0Ovw%40mail.gmail.com.