ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
199 stars 153 forks source link

win_dns_record - CNAME in a subdomain is not created properly #429

Closed JLE-ATS closed 1 year ago

JLE-ATS commented 2 years ago
SUMMARY

I have tried to create a CNAME record in a subdomain. Instead of adding the record in the existing subdomain, the module recreate an arborescence of subdomain in which the record is created.

ISSUE TYPE
COMPONENT NAME

win_dns_record

ANSIBLE VERSION
ansible 2.10.8
  config file = /opt/ansible/ansible/ansible.cfg
  configured module search path = ['/opt/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
COLLECTION VERSION
# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.windows 1.3.0

# /opt/ansible/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.windows 1.7.0
CONFIGURATION
DEFAULT_BECOME(/opt/ansible/ansible/ansible.cfg) = False
DEFAULT_BECOME_ASK_PASS(/opt/ansible/ansible/ansible.cfg) = False
DEFAULT_BECOME_METHOD(/opt/ansible/ansible/ansible.cfg) = sudo
DEFAULT_BECOME_USER(/opt/ansible/ansible/ansible.cfg) = root
DEFAULT_HOST_LIST(/opt/ansible/ansible/ansible.cfg) = ['/opt/ansible/ansible/inventory']
DEFAULT_REMOTE_USER(/opt/ansible/ansible/ansible.cfg) = ansible
HOST_KEY_CHECKING(/opt/ansible/ansible/ansible.cfg) = False
OS / ENVIRONMENT
STEPS TO REPRODUCE

Based on the following example :

Use

- name: Create the server alias
    community.windows.win_dns_record:
      name: "helloworld.test"
      type: "CNAME"
      value: "myserver.example.com"
      zone: "example.com"
EXPECTED RESULTS

The expected result is the creation of a CNAME record named "helloworld" in the subdomain "test" of the domain "example.com". This record should point to the host myserver.example.com.

ACTUAL RESULTS

In the domain "example.com", I get a new subdomain named "com", under which I get a new subdomain named "example", under which I get a new subdomain named "test", under which I find the record "helloworld".

PROPOSED SOLUTION

After taking a look at the module code, I think the behaviour could be fixed by adding a specific case for CNAME in this try/catch. I have found there is a powershell module dedicated to CNAME record.

The following powershell command is able to create te required CNAME : Add-DnsServerResourceRecordCName -Name "helloworld.test" -HostNameAlias "myserver.example.com" -ZoneName "example.com"

So we could add something like :

elseif ($type -eq 'CNAME') {
    Add-DnsServerResourceRecordCName -Name $name -HostNameAlias $value -ZoneName $zone
}

I think the extra arguments are also compatible with this powershell module, but I am not sure.

Change to documentation :