Infoblox’s global team of threat hunters uncovers a DNS operation with the ability to bypass traditional security measures and control the Great Firewall of China. Read about “Muddling Meerkat” and the many other threat actors discovered by Infoblox Threat Intel here.

API & Integration, DevOps,NetOps,SecOps

Reply

Ansible loop through variable list and lookup CNAME records

[ Edited ]
Authority
Posts: 18
697     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