ansible-collections / community.dns

Ansible modules and plugins for working with DNS
https://galaxy.ansible.com/ui/repo/published/community/dns/
GNU General Public License v3.0
27 stars 19 forks source link

community.dns.hetzner_dns_records **inventory plugin** loses data #132

Closed nklamann closed 1 year ago

nklamann commented 1 year ago
SUMMARY

community.dns.hetzner_dns_records inventory plugin return data does not show all relevant data

ISSUE TYPE
COMPONENT NAME

community.dns.hetzner_dns_records inventory plugin

ANSIBLE VERSION
ansible [core 2.14.0]
  config file = /mnt/i/ansible/neuaufbau/ansible/ansible.cfg
  configured module search path = ['/home/norbert/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/norbert/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/norbert/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/norbert/.local/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3)
  jinja version = 3.0.1
  libyaml = True
COLLECTION VERSION
# /home/norbert/.ansible/collections/ansible_collections
Collection    Version
------------- -------
community.dns 2.4.2  
CONFIGURATION
CACHE_PLUGIN(/mnt/i/ansible/neuaufbau/ansible/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/mnt/i/ansible/neuaufbau/ansible/ansible.cfg) = facts
CACHE_PLUGIN_PREFIX(/mnt/i/ansible/neuaufbau/ansible/ansible.cfg) = ansible_facts.
CONFIG_FILE() = /mnt/i/ansible/neuaufbau/ansible/ansible.cfg
DEFAULT_GATHERING(/mnt/i/ansible/neuaufbau/ansible/ansible.cfg) = explicit
DEFAULT_HOST_LIST(/mnt/i/ansible/neuaufbau/ansible/ansible.cfg) = ['/mnt/i/ansible/neuaufbau/ansible/inventory/hosts']
DEFAULT_PRIVATE_KEY_FILE(/mnt/i/ansible/neuaufbau/ansible/ansible.cfg) = /mnt/i/ansible/hetzner/.ssh/Ansible20210507
DEFAULT_REMOTE_PORT(/mnt/i/ansible/neuaufbau/ansible/ansible.cfg) = 40022
DEFAULT_REMOTE_USER(/mnt/i/ansible/neuaufbau/ansible/ansible.cfg) = ansible
OS / ENVIRONMENT

WSL2 debian 11 under Windows 10

STEPS TO REPRODUCE

A DNS entry at hetrzner consists of the 'fields' TYPE, NAME and VALUE.

When I want to get information about a zone with the inventory plugin community.dns.hetzner_dns_records I get a list of jsons structures keyed by the concatenation of VALUE and zone_name , each contains a field ansible_host , which contains the VALUE in the record and a field mail_relay ,which is a host_var in my local ansible configuration and has nothing to do with hetzner .

This has 2 important problems:

This is difficult to work with when only one type of DNS data is required , but the module allows a list of Tpes and then it is impossible to say which result is which TYPE.

But the not uniqueness of the key is the real problem here and makes the ouput wrong, existing records are silently ignored.

plugin: community.dns.hetzner_dns_records
hetzner_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zone_name: klamann-service.de
filters:
  type:
    - CNAME
    - A
    - AAAA

Command was

ansible-inventory  -i inventory/hetzner.hetzner_dns.yml  --list | jq '._meta.hostvars'
EXPECTED RESULTS

a list of entries, each containing TYPE, NAME, VALUE (and zone_name for good measure, the the inventory could contain several zoens in one go) containing this information ( ('klamann-service.de','@','A','an IP') ,('klamann-service.de','cloud2','A','an IP') ,('klamann-service.de','mail','A','an IP') ,('klamann-service.de','@','AAAA','an IP') ,('klamann-service.de','cloud2','AAAA','an IP') ,('klamann-service.de','mail','AAAA','an IP') ,('klamann-service.de','fossil','CNAME','cloud2') ,('klamann-service.de','webmail','CNAME','mail')

)

or a list of dictioanaries

or a dictionary as now containing a list of dictionaries.

ACTUAL RESULTS

Only 3 records delivered because wrong key , type info not available, spurious variable (mail_ralay) from local configuration .

{
  "cloud2.klamann-service.de": {
    "ansible_host": "an IP",
    "mail_relay": true
  },
  "klamann-service.de": {
    "ansible_host": "an IP",
    "mail_relay": true
  },
  "mail.klamann-service.de": {
    "ansible_host": "an IPV6",
    "mail_relay": true
  }
}
nklamann commented 1 year ago

Maybe it makes sense to return the TTL too ? And/ or the MX priority. This gets crazy fast ....

nklamann commented 1 year ago

The functionality i look for is in community.dns.hetzner_dns_record_set_info

    - name: Query all records for www.example.com
      community.dns.hetzner_dns_record_set_info:
        zone_name: klamann-service.de
        what: all_records
      register: records
    - name: "show records"
      ansible.builtin.debug:
        var: records
felixfontein commented 1 year ago

The inventory plugin is for composing Ansible inventories, for example if you want to find the servers you want to run something on by looking in a DNS zone. As you correctly noticed, there are other modules that retrieve the list of (all) DNS records, if you are simply interested in the raw records.