ansible-collections / community.windows

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

win_dns_record: Unhandled exception while executing module: Failed to remove resource record #500

Open semlohnayr opened 1 year ago

semlohnayr commented 1 year ago
SUMMARY

Trying to delete records (state: absent) using community.windows.win_dns_record results in a task failure but the actual record gets deleted. If I rerun the task to delete the record, ok is returned. I do not have any issues adding dns records.

ISSUE TYPE
COMPONENT NAME

community.windows.win_dns_record version 1.12.0

ANSIBLE VERSION
2.13.5
COLLECTION VERSION
community.windows 1.12.0
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS
rhochmayr commented 1 year ago

Hi There

We are seeing the same issue when running following step:

name: "{{ server_name }}"  
type: "A"  
state: absent  
zone: "{{ dns_domain }}"  
computer_name: "{{ dns_domain }}"  

Here is our cleaned-up output:

{
  "exception": "Failed to remove resource record <servername> from zone <zone> on server <computername>\nAt line:86 char:23\r\n+ ...   $record | Remove-DnsServerResourceRecord -ZoneName $zone -Force -Wh ...\r\n+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n    + CategoryInfo          : NotSpecified: (<servername>:root/Microsoft/...rResourceRecord) [Remove-DnsServerResourceRecord], CimException\n    + FullyQualifiedErrorId : WIN32 9715,Remove-DnsServerResourceRecord\r\n\r\nScriptStackTrace:\r\n\r\n\r\nMicrosoft.Management.Infrastructure.CimException: Failed to remove resource record <servername> from zone <zone> on server <computername>\r\n   at Microsoft.Management.Infrastructure.Internal.Operations.CimAsyncObserverProxyBase1.ProcessNativeCallback(OperationCallbackProcessingContext callbackProcessingContext, T currentItem, Boolean moreResults, MiResult operationResult, String errorMessage, InstanceHandle errorDetailsHandle)",
  "msg": "Unhandled exception while executing module: Failed to remove resource record <servername> from zone <zone> on <computername>",
  "_ansible_no_log": false,
  "changed": false,
  "_ansible_delegated_vars": {
    "ansible_host": "<ansible-host>",
    "ansible_port": 5986,
    "ansible_user": "<username>",
    "ansible_connection": "<connection>"
  }
}

Oddly enough WIN32 9715 seems to reference an error when creating a PTR record. Not sure how this is related when Removing an A record. https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--9000-11999-

So far we have seen the issue come up when there is no existing reverse zone for the address of the A record that should be deleted.

However, we tried to reproduce the issue in another environment, and there a missing reverse zone didn't cause a problem. It's been a very intermittend issue so far.

Thanks Rob

rhochmayr commented 1 year ago

Hi again

Just a quick update, in our case it turned out to be a permission issue on some reverse zones wich caused the error to come up when deleting the A record, wich in turn automatically also tries to remove the respective reverse record.

So this issue, at least in our case, was not related to the ansbible module as such since we were able to reproduce it with native tools als well.

Thanks Robert