Skip to content

Commit

Permalink
win_service_info - ignore file not found errors (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
jborean93 authored Oct 3, 2023
1 parent 6921450 commit 1a4307d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/win_service_info-not-found.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions plugins/modules/win_service_info.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1a4307d

Please sign in to comment.