diff --git a/changelogs/fragments/win_reg_stat-hku.yaml b/changelogs/fragments/win_reg_stat-hku.yaml new file mode 100644 index 00000000000..5008dd1ef0d --- /dev/null +++ b/changelogs/fragments/win_reg_stat-hku.yaml @@ -0,0 +1,2 @@ +bugfixes: +- win_reg_stat - fix issue when trying to check keys in ``HKU:\`` - https://github.com/ansible/ansible/issues/59337 diff --git a/lib/ansible/modules/windows/win_reg_stat.ps1 b/lib/ansible/modules/windows/win_reg_stat.ps1 index aa7e4ba3147..c31fc5a8693 100644 --- a/lib/ansible/modules/windows/win_reg_stat.ps1 +++ b/lib/ansible/modules/windows/win_reg_stat.ps1 @@ -80,7 +80,7 @@ $registry_hive = switch(Split-Path -Path $path -Qualifier) { "HKCC:" { [Microsoft.Win32.Registry]::CurrentConfig } "HKCU:" { [Microsoft.Win32.Registry]::CurrentUser } "HKLM:" { [Microsoft.Win32.Registry]::LocalMachine } - "HKU" { [Microsoft.Win32.Registry]::Users } + "HKU:" { [Microsoft.Win32.Registry]::Users } } $key = $null diff --git a/test/integration/targets/win_reg_stat/tasks/tests.yml b/test/integration/targets/win_reg_stat/tasks/tests.yml index 285b501a4ad..5424ba4d45b 100644 --- a/test/integration/targets/win_reg_stat/tasks/tests.yml +++ b/test/integration/targets/win_reg_stat/tasks/tests.yml @@ -362,3 +362,16 @@ assert: that: - not actual.exists + +# Tests https://github.com/ansible/ansible/issues/59337 +- name: test out all registry hives + win_reg_stat: + path: '{{ item }}' + register: reg_hive_stat + failed_when: not reg_hive_stat.exists + with_items: + - HKCR:\* + - HKCC:\Software + - HKCU:\Software + - HKLM:\Software + - HKU:\.DEFAULT