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.
pull/44054/head
Daniel Sánchez Fábregas 6 years ago
parent 77bff99f3c
commit f583656985

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

Loading…
Cancel
Save