diff --git a/lib/ansible/modules/extras/windows/win_regedit.ps1 b/lib/ansible/modules/extras/windows/win_regedit.ps1 index f4975dea224..723a6c7b239 100644 --- a/lib/ansible/modules/extras/windows/win_regedit.ps1 +++ b/lib/ansible/modules/extras/windows/win_regedit.ps1 @@ -42,6 +42,13 @@ If ($state -eq "present" -and $registryData -eq $null -and $registryValue -ne $n Fail-Json $result "missing required argument: data" } +# check the registry key is in powershell ps-drive format: HKLM, HKCU, HKU, HKCR, HCCC +If (-not ($registryKey -match "^H[KC][CLU][MURC]{0,1}:\\")) +{ + Fail-Json $result "key: $registryKey is not a valid powershell path, see module documentation for examples." +} + + Function Test-RegistryValueData { Param ( [parameter(Mandatory=$true)] @@ -58,8 +65,8 @@ Function Test-RegistryValueData { } } -# Returns rue if registry data matches. -# Handles binary and string registry data +# Returns true if registry data matches. +# Handles binary, integer(dword) and string registry data Function Compare-RegistryData { Param ( [parameter(Mandatory=$true)] @@ -67,15 +74,14 @@ Function Compare-RegistryData { [parameter(Mandatory=$true)] [AllowEmptyString()]$DifferenceData ) - $refType = $ReferenceData.GetType().Name - if ($refType -eq "String" ) { + if ($ReferenceData -is [String] -or $ReferenceData -is [int]) { if ($ReferenceData -eq $DifferenceData) { return $true } else { return $false } - } elseif ($refType -eq "Object[]") { + } elseif ($ReferenceData -is [Object[]]) { if (@(Compare-Object $ReferenceData $DifferenceData -SyncWindow 0).Length -eq 0) { return $true } else { @@ -118,7 +124,7 @@ else } -if($registryDataType -eq "binary" -and $registryData -ne $null -and $registryData.GetType().Name -eq 'String') { +if($registryDataType -eq "binary" -and $registryData -ne $null -and $registryData -is [String]) { $registryData = Convert-RegExportHexStringToByteArray($registryData) } diff --git a/lib/ansible/modules/extras/windows/win_regedit.py b/lib/ansible/modules/extras/windows/win_regedit.py index 8845f8ceb9f..d9de288e687 100644 --- a/lib/ansible/modules/extras/windows/win_regedit.py +++ b/lib/ansible/modules/extras/windows/win_regedit.py @@ -126,6 +126,12 @@ EXAMPLES = ''' key: HKCU:\Software\MyCompany value: hello state: absent + + # Ensure registry paths containing spaces are quoted. + # Creates Registry Key called 'My Company'. + win_regedit: + key: 'HKCU:\Software\My Company' + ''' RETURN = ''' data_changed: