- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Lookup to create a list of extattrs
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2021 11:24 AM
I have a lookup that shows the output of my extensible attributes but I only want to see the output of the Origin_AS. I need to make a list of all the Origin_AS numbers.
Here's the lookup.
"host_records": [
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuMTYuMjA4LjQwLzMwLzA:10.x.x.x/30/default",
"extattrs": {
"CL_RTR_INT": [
"Router A",
"WAN Network _30"
],
"Client_Site_#": "81_002-(Seattle, WA)",
"Network_Container": "NG",
"Network_Environment": "CLIENT_REMOTE",
"Network_Name": "ansible_test_assignment",
"Origin_AS": "690001", <--- I only want the output to be 690001
"VRF_NAME": "CL"
}
},
]
Solved! Go to Solution.
Re: Lookup to create a list of extattrs
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2021 10:36 PM
Hi,
You can use "with_items" to parse the list first before indexing the dictionary object.
Maybe you can try this approach:
- name: ASN set_fact: host_records: "{{ lookup('nios', 'network', filter={'*Origin_AS~': '69'}, return_fields=['extattrs'], provider=cli_infoblox ) }}" - name: ASN output debug: msg: "{{ item['extattrs']['Origin_AS'] }}" with_items: - "{{ host_records }}"
Hope this helps!
Thanks and Regards
Vedant Sethia
Re: Lookup to create a list of extattrs
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2021 06:23 AM - edited 05-24-2021 06:24 AM
I tried you solution and I think it partially gives me what I want. This is the output.
ok: [10.x.x.22] => (item={'_ref': 'network/ZG5zLm5ldHdvcmskMTAuMTcuMjA4LjE1Ni8zMC8w:10.17.208.156/30/default', 'extattrs': {'CL_RTR_INT': ['Router A', 'WAN Network _30'], 'Client_Site_#': 'A00000-test_site - (JAX, FL)', 'Network_Container': 'NG', 'Network_Environment': 'CLIENT_REMOTE', 'Network_Name': 'ansible_test_assignment', 'Origin_AS': '690001', 'VRF_NAME': 'CL'}}) => {
"msg": "690001"
}
So I'm now getting the Origin_AS for each record so now how would I make a list of these values. Something like this...
690001
690003
690009
690201
,Re: Lookup to create a list of extattrs
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2021 01:35 AM
Hi,
This might give you what you are looking for:
- name: ASN set_fact: host_records: "{{ lookup('nios', 'network', filter={'*Origin_AS~': '69'}, return_fields=['extattrs'], provider=cli_infoblox ) }}" result: [] - name: ASN Process set_fact: result: "{{ result + [item['extattrs']['Origin_AS']] }}" with_items: - "{{ host_records }}" - name: ASN Output debug: var=result
Hope this Helps!
Thanks and Regards
Vedant Sethia