From 1a4307d2fa2fb17926de529dd7a853ebb8b4c469 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Tue, 3 Oct 2023 14:34:31 -0400 Subject: [PATCH] win_service_info - ignore file not found errors (#559) --- changelogs/fragments/win_service_info-not-found.yml | 2 ++ plugins/modules/win_service_info.ps1 | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/win_service_info-not-found.yml diff --git a/changelogs/fragments/win_service_info-not-found.yml b/changelogs/fragments/win_service_info-not-found.yml new file mode 100644 index 00000000..2e8a78c3 --- /dev/null +++ b/changelogs/fragments/win_service_info-not-found.yml @@ -0,0 +1,2 @@ +bugfixes: +- win_service_info - Warn and not fail if ERROR_FILE_NOT_FOUND when trying to query a service - https://github.com/ansible-collections/ansible.windows/issues/556 diff --git a/plugins/modules/win_service_info.ps1 b/plugins/modules/win_service_info.ps1 index c87538f3..dfe18447 100644 --- a/plugins/modules/win_service_info.ps1 +++ b/plugins/modules/win_service_info.ps1 @@ -33,9 +33,12 @@ $module.Result.services = @( ) } catch [Ansible.Windows.SCManager.ServiceManagerException] { - # ERROR_ACCESS_DENIED, ignore the service and continue on. - if ($_.Exception.InnerException -and $_.Exception.InnerException.NativeErrorCode -eq 5) { - $msg = "Failed to access service '$($rawService.Name) to get more info, ignoring: $($_.Exception.Message)" + # ERROR_FILE_NOT_FOUND (2) - Unsure why this happens but probably + # the description or some other text field refers to a shared + # resource string. + # ERROR_ACCESS_DENIED (5) + if ($_.Exception.InnerException -and $_.Exception.InnerException.NativeErrorCode -in @(2, 5)) { + $msg = "Failed to open service '$($rawService.Name) to get more info, ignoring: $($_.Exception.Message)" $module.Warn($msg) continue }