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

community.windows.win_dns_record - param computer_name ignored #432

Closed derhoeppi closed 2 years ago

derhoeppi commented 2 years ago
SUMMARY

I want to use this module to create / remove dns records from Microsoft Domain Controllers with integrated DNS. If i use this module on a system where RSAT with DNS is installed - it does not use the param computer_name. We does not directly connect to a DC.

ISSUE TYPE
COMPONENT NAME

community.windows.win_dns_record

ANSIBLE VERSION
ansible [core 2.11.4]
COLLECTION VERSION
1.11
STEPS TO REPRODUCE
  1. Create a user that is allowed to create, delete and modify dns records
  2. Install RSAT on a separate system that could connect to the DC's
  3. Test Get-DNS Get-DnsServerResourceRecord to retriev DNS information
  4. Use the following playbook to automate with ansible
---
- name: Test dns records
  hosts: myrsatsystem.my.domain
  gather_facts: false

  tasks:
    - name: Create DNS record
      community.windows.win_dns_record:
        computer_name: mydc.my.domain
        name: "mytest"
        type: "A"
        value: "192.168.0.1"
        zone: "my.domain"
EXPECTED RESULTS

This playbook should be finish successfull.

ACTUAL RESULTS
The full traceback is:
Failed to get the zone information for nat.tc on server myrsatsystem.
At line:73 char:12
+ $records = Get-DnsServerResourceRecord -ZoneName $zone -Name $name -R ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (nat.tc:root/Microsoft/...rResourceRecord) [Get-DnsServerResourceRecord], CimException
    + FullyQualifiedErrorId : WIN32 1722,Get-DnsServerResourceRecord

ScriptStackTrace:
at Get-DnsServerResourceRecord<End>, <No file>: line 4075
at <ScriptBlock>, <No file>: line 73

Microsoft.Management.Infrastructure.CimException: Failed to get the zone information for nat.tc on server myrsatsystem.
   at Microsoft.Management.Infrastructure.Internal.Operations.CimAsyncObserverProxyBase`1.ProcessNativeCallback(OperationCallbackProcessingContext callbackProcessingContext, T currentItem, Boolean moreResults, MiResult operationResult, String errorMessage, InstanceHandle errorDetailsHandle)
fatal: [myrsatsystem.my.domain]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: Failed to get the zone information for nat.tc on server myrsatsystem.my.domain."
}

I think the source of my error is located in https://github.com/ansible-collections/community.windows/blob/main/plugins/modules/win_dns_record.ps1 on line 74

$records = Get-DnsServerResourceRecord -ZoneName $zone -Name $name -RRType $type -Node -ErrorAction:Ignore @extra_args | Sort-Object

The given param computer_name is not used there. I can only find an rewrite of the ansible param but nothing happens with this param inside the ps1 file.

derhoeppi commented 2 years ago

Sorry - my mistake. This problem was fixed in release 1.0.7. My dev station has an old version installed