diff options
author | Jordan Borean <jborean93@gmail.com> | 2019-11-13 12:45:39 +1000 |
---|---|---|
committer | Matt Davis <nitzmahone@users.noreply.github.com> | 2019-11-12 18:45:39 -0800 |
commit | 59f417c46984e9304019c96330f8a0d7c5fc1f3e (patch) | |
tree | 9d65e9895924bd63172e41b25442ba00542829a6 | |
parent | 2dbe024fcbafdf22e200cb44060a14e36c7534f7 (diff) | |
download | ansible-59f417c46984e9304019c96330f8a0d7c5fc1f3e.tar.gz |
Corrected Get-adcomputer (#63093) (#64755)
* Corrected Get-adcomputer
Corrected Get-adcomputer on "Remove-ConstructedState" and "Set-ConstructedState" functions.
resolved error: Unable to contact the server. This may be because this server does not exist, it is currently down, or it does not have the Active Directory Web Services running.
* Update lib/ansible/modules/windows/win_domain_computer.ps1
Co-Authored-By: Daniel-Sanchez-Fabregas <33929811+Daniel-Sanchez-Fabregas@users.noreply.github.com>
* Update win_domain_computer.ps1
changed
"-credential $credential" to "@extra_args" (Line 115 and 150)
corrected exception message (Line 122)
* Added changelog fragment, minor code tweak
(cherry picked from commit e77426dad36426bf80784e99d1a0c1caee3ba0da)
-rw-r--r-- | changelogs/fragments/win_domain_computer-credential.yaml | 2 | ||||
-rw-r--r-- | lib/ansible/modules/windows/win_domain_computer.ps1 | 16 |
2 files changed, 10 insertions, 8 deletions
diff --git a/changelogs/fragments/win_domain_computer-credential.yaml b/changelogs/fragments/win_domain_computer-credential.yaml new file mode 100644 index 0000000000..ebcd884f94 --- /dev/null +++ b/changelogs/fragments/win_domain_computer-credential.yaml @@ -0,0 +1,2 @@ +bugfixes: +- win_domain_computer - Honour the explicit domain server and credentials when moving or removing a computer object - https://github.com/ansible/ansible/pull/63093 diff --git a/lib/ansible/modules/windows/win_domain_computer.ps1 b/lib/ansible/modules/windows/win_domain_computer.ps1 index f53f46b595..86c380e8ff 100644 --- a/lib/ansible/modules/windows/win_domain_computer.ps1 +++ b/lib/ansible/modules/windows/win_domain_computer.ps1 @@ -112,14 +112,14 @@ Function Set-ConstructedState($initial_state, $desired_state) { If ($initial_state.distinguished_name -cne $desired_state.distinguished_name) { # Move computer to OU Try { - Get-ADComputer -Identity $desired_state.name | + Get-ADComputer -Identity $desired_state.name @extra_args | Move-ADObject ` -TargetPath $desired_state.ou ` -Confirm:$False ` -WhatIf:$check_mode ` @extra_args } Catch { - Fail-Json -obj $result -message "Failed to move the AD object $($desired_state.name) to $($desired_state.ou) OU: $($_.Exception.Message)" + Fail-Json -obj $result -message "Failed to move the AD object $($initial_state.distinguished_name) to $($desired_state.distinguished_name): $($_.Exception.Message)" } } $result.changed = $true @@ -147,12 +147,12 @@ Function Add-ConstructedState($desired_state) { # ------------------------------------------------------------------------------ Function Remove-ConstructedState($initial_state) { Try { - Get-ADComputer $initial_state.name ` - | Remove-ADObject ` - -Recursive ` - -Confirm:$False ` - -WhatIf:$check_mode ` - @extra_args + Get-ADComputer -Identity $initial_state.name @extra_args | + Remove-ADObject ` + -Recursive ` + -Confirm:$False ` + -WhatIf:$check_mode ` + @extra_args } Catch { Fail-Json -obj $result -message "Failed to remove the AD object $($desired_state.name): $($_.Exception.Message)" } |