Fix win_domain_computer error when empty description (#44627)

* Fix win_domain_computer

 Fixes #43653

- Change descrtiption parameter default to null.
  When reading an empty description from AD, powershell returns a null.
- Convert after and before diff keys to ordered hashes.
  Unordered state descriptions make --diff report equal values as
  changes.

(cherry picked from commit f583656985)

* Add changelog
pull/44522/head
Daniel-Sanchez-Fabregas 6 years ago committed by Matt Clay
parent d7a7295c81
commit 9e34ba0a7e

@ -0,0 +1,3 @@
bugfixes:
- win_domain_computer - fixed error when description parameter is empty (https://github.com/ansible/ansible/pull/44054)
- win_domain_computer - fixed error in diff_support

@ -25,14 +25,14 @@ If (-not $sam_account_name.EndsWith("$")) {
Fail-Json -obj $result -message "sam_account_name must end in $"
}
$enabled = Get-AnsibleParam -obj $params -name "enabled" -type "bool" -default $true
$description = Get-AnsibleParam -obj $params -name "description" -default ""
$description = Get-AnsibleParam -obj $params -name "description" -default $null
$state = Get-AnsibleParam -obj $params -name "state" -ValidateSet "present","absent" -default "present"
If ($state -eq "present") {
$dns_hostname = Get-AnsibleParam -obj $params -name "dns_hostname" -failifempty $true -resultobj $result
$ou = Get-AnsibleParam -obj $params -name "ou" -failifempty $true -resultobj $result
$distinguished_name = "CN=$name,$ou"
$desired_state = @{
$desired_state = [ordered]@{
name = $name
sam_account_name = $sam_account_name
dns_hostname = $dns_hostname
@ -43,7 +43,7 @@ If ($state -eq "present") {
state = $state
}
} Else {
$desired_state = @{
$desired_state = [ordered]@{
name = $name
state = $state
}
@ -58,7 +58,7 @@ Function Get-InitialState($desired_state) {
-Properties DistinguishedName,DNSHostName,Enabled,Name,SamAccountName,Description,ObjectClass
} Catch { $null }
If ($computer) {
$initial_state = @{
$initial_state = [ordered]@{
name = $computer.Name
sam_account_name = $computer.SamAccountName
dns_hostname = $computer.DNSHostName
@ -70,7 +70,7 @@ Function Get-InitialState($desired_state) {
state = "present"
}
} Else {
$initial_state = @{
$initial_state = [ordered]@{
name = $desired_state.name
state = "absent"
}

Loading…
Cancel
Save