diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:35 +0000 |
commit | 7fec0b69a082aaeec72fee0612766aa42f6b1b4d (patch) | |
tree | efb569b86ca4da888717f5433e757145fa322e08 /ansible_collections/microsoft/ad/plugins/modules/membership.ps1 | |
parent | Releasing progress-linux version 7.7.0+dfsg-3~progress7.99u1. (diff) | |
download | ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.tar.xz ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.zip |
Merging upstream version 9.4.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/microsoft/ad/plugins/modules/membership.ps1')
-rw-r--r-- | ansible_collections/microsoft/ad/plugins/modules/membership.ps1 | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/ansible_collections/microsoft/ad/plugins/modules/membership.ps1 b/ansible_collections/microsoft/ad/plugins/modules/membership.ps1 index 2b37bcdfd..d2be34e9f 100644 --- a/ansible_collections/microsoft/ad/plugins/modules/membership.ps1 +++ b/ansible_collections/microsoft/ad/plugins/modules/membership.ps1 @@ -207,7 +207,27 @@ if ($state -eq 'domain') { $joinParams.OUPath = $domainOUPath } - Add-Computer @joinParams + try { + Add-Computer @joinParams + } + catch { + $failMsg = [string]$_ + + # The error if the domain_ou_path does not exist is a bit + # vague, we try to catch that specific error type and provide + # a more helpful hint to what is wrong. As the exception does + # not have an error code to check, we compare the Win32 error + # code message with a localized variant for + # ERROR_FILE_NOT_FOUND. .NET Framework does not end with . + # whereas .NET 5+ does so we use regex to match both patterns. + # https://github.com/ansible-collections/microsoft.ad/issues/88 + $fileNotFound = [System.ComponentModel.Win32Exception]::new(2).Message + if ($_.Exception.Message -match ".*$([Regex]::Escape($fileNotFound))\.?`$") { + $failMsg += " Check domain_ou_path is pointing to a valid OU in the target domain." + } + + $module.FailJson($failMsg, $_) + } $module.Result.changed = $true $module.Result.reboot_required = $true |