Introducing SOC Insights for BloxOne Threat Defense: Boost your SOC efficiency with AI-driven insights to eliminate manual work and accelerate investigation and response times. Read the blog announcement here.

API & Integration, DevOps,NetOps,SecOps

Reply

Lookup to create a list of extattrs

Authority
Posts: 18
2281     0

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.

 

    - name: ASN
      set_fact:
         host_records: "{{ lookup('nios', 'network', filter={'*Origin_AS~': '69'}, return_fields=['extattrs'], provider=cli_infoblox ) }}"

    - name: ASN output
      debug:
        msg: "{{ host_records.extattrs[5] }}"     - this gives an error that extattrs is not attribute
 
Here's the output if the debug msg is host_records:
 
"ansible_facts": {
"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"
}
},
]

Re: Lookup to create a list of extattrs

New Member
Posts: 5
2282     0

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 ]
Authority
Posts: 18
2282     0

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

New Member
Posts: 5
2282     0

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

Showing results for 
Search instead for 
Did you mean: 

Recommended for You

Businesses are investing heavily into securing company resources from cyber-attacks form cybercrimin