summaryrefslogtreecommitdiffstats
path: root/ansible_collections/microsoft/ad/plugins/modules/membership.ps1
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
commit7fec0b69a082aaeec72fee0612766aa42f6b1b4d (patch)
treeefb569b86ca4da888717f5433e757145fa322e08 /ansible_collections/microsoft/ad/plugins/modules/membership.ps1
parentReleasing progress-linux version 7.7.0+dfsg-3~progress7.99u1. (diff)
downloadansible-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.ps122
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