From 888de842b3813f6702c4c3ba537a5b3b062babbc Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Tue, 17 Oct 2017 11:58:32 +1000 Subject: [PATCH] win_regedit: fix extra info coming into stdout (#31813) --- lib/ansible/modules/windows/win_regedit.ps1 | 4 +- .../targets/win_regedit/tasks/tests.yml | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/windows/win_regedit.ps1 b/lib/ansible/modules/windows/win_regedit.ps1 index a3ee499628..e270ec04ad 100644 --- a/lib/ansible/modules/windows/win_regedit.ps1 +++ b/lib/ansible/modules/windows/win_regedit.ps1 @@ -243,7 +243,7 @@ if ($state -eq "present") { if (-not (Test-Path -path $path)) { # the key doesn't exist, create it so the next steps work try { - New-Item -Path $path -Type directory -Force -WhatIf:$check_mode + $null = New-Item -Path $path -Type directory -Force -WhatIf:$check_mode } catch { Fail-Json $result "failed to create registry key at $($path): $($_.Exception.Message)" } @@ -330,7 +330,7 @@ $key_prefix[$path] if ($delete_key -and $name -eq $null) { # the clear_key flag is set and name is null so delete the entire key try { - Remove-Item -Path $path -Force -Recurse -WhatIf:$check_mode + $null = Remove-Item -Path $path -Force -Recurse -WhatIf:$check_mode } catch { Fail-Json $result "failed to delete registry key at $($path): $($_.Exception.Message)" } diff --git a/test/integration/targets/win_regedit/tasks/tests.yml b/test/integration/targets/win_regedit/tasks/tests.yml index 17e66d4d7c..1e39de566f 100644 --- a/test/integration/targets/win_regedit/tasks/tests.yml +++ b/test/integration/targets/win_regedit/tasks/tests.yml @@ -421,3 +421,40 @@ assert: that: - not create_hkcr_key_again|changed + +# https://github.com/ansible/ansible/issues/31782 +- name: create property like a json string + win_regedit: + path: '{{test_win_regedit_local_key}}\NewKey' + name: '{7f51bda7-bcea-465a-9eb6-5a2bcd9cb52f}' + data: test data + type: string + state: present + register: create_prop_with_json + +- name: get result of create property like a json string + win_reg_stat: + path: '{{test_win_regedit_local_key}}\NewKey' + name: '{7f51bda7-bcea-465a-9eb6-5a2bcd9cb52f}' + register: create_prop_with_json_result + +- name: assert results of create property like a json string + assert: + that: + - create_prop_with_json|changed + - create_prop_with_json_result.exists == True + - create_prop_with_json_result.value == 'test data' + +- name: create property like a json string (idempotent) + win_regedit: + path: '{{test_win_regedit_local_key}}\NewKey' + name: '{7f51bda7-bcea-465a-9eb6-5a2bcd9cb52f}' + data: test data + type: string + state: present + register: create_prop_with_json_again + +- name: assert results of create property like a json string (idempotent) + assert: + that: + - not create_prop_with_json_again|changed