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

Ansible loop through variable list and lookup CNAME records

[ Edited ]
Authority
Posts: 18
637     0

 

Trying to loop over the CNAME records and use the canonical name to lookup the A records.  The lookup for the CNAME is working great but when the Get A Record by Canonical task runs it is only picking up a single canonical name when the results of the CNAME lookup is presenting two.  This is an issue with the loop I understand but I can't seem to fix the issue.  I'm currently testing with two FQDN and this is the output from the CNAME lookup.  Right now I'm only getting the last entry from FQDN.

 

{
"changed": false,
"ansible_facts": {
"record_fqdn": [
{
"_ref": "record:cname/ZG5zLmJpbmRfY25hbWUkLjIxLmNvbS5ia2ljb25uZWN0LmNoYXNlZW1wb3dlcmxlbmRpbmc:test.com/Acme",
"canonical": "test.com"
}
]
},


{
"changed": false,
"ansible_facts": {
"record_fqdn": [
{
"_ref": "record:cname/ZG5zLmJpbmRfY25hbWUkLjIxLmNvbS5ia2ljb25uZWN0LmVtcG93ZXJsb3M:test1.com/Acme",
"canonical": "TEST1.COM"
}
]
},

 

This my lookup tasks:

 

    - name: Get CNAME Record by FQDN
      set_fact:
        record_fqdn: "{{ lookup('nios', 'record:cname', filter={'name': item, 'view': 'Acme'}, return_fields=['extattrs', 'name', 'view', 'canonical' ], provider=nios_provider, wantlist=True) }}"
      loop: "{{ fqdn }}"
      when: fqdn | length > 0
      tags: fqdn
    
    - name: A Record Lookup
      set_fact: 
        records: "{{ records  | default([]) + lookup('nios', 'record:a', filter={'name': item.canonical, 'view': 'Acme'}, return_fields=['ipv4addr'], provider=nios_provider, wantlist=True) }}"
      loop: "{{ record_fqdn | lower }}"
Showing results for 
Search instead for 
Did you mean: 

Recommended for You