From f2bd6b6bfd8508e03fdcbbda79bf4aeb07c67e8d Mon Sep 17 00:00:00 2001 From: jamessemai Date: Wed, 27 Jun 2018 01:13:31 +0200 Subject: [PATCH] win_security_policy: allow removing values (resolves #40869) (#41125) * win_security_policy: allow removing values (resolves #40869) * Removing warning * Adding test for remove policy setting * Fixing string comparison --- .../modules/windows/win_security_policy.ps1 | 2 + .../win_security_policy/tasks/tests.yml | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/ansible/modules/windows/win_security_policy.ps1 b/lib/ansible/modules/windows/win_security_policy.ps1 index 2381d0e4b9..43a859b720 100644 --- a/lib/ansible/modules/windows/win_security_policy.ps1 +++ b/lib/ansible/modules/windows/win_security_policy.ps1 @@ -194,6 +194,8 @@ if ($will_change -eq $true) { if ($new_value -cne $value) { Fail-Json $result "Failed to change the value for key '$key' in section '$section', the value is still $new_value" } + } elseif ([string]$value -eq "") { + # Value was empty, so OK if no longer in the result } else { Fail-Json $result "The key '$key' in section '$section' is not a valid key, cannot set this value" } diff --git a/test/integration/targets/win_security_policy/tasks/tests.yml b/test/integration/targets/win_security_policy/tasks/tests.yml index 1afa534269..5ea341025f 100644 --- a/test/integration/targets/win_security_policy/tasks/tests.yml +++ b/test/integration/targets/win_security_policy/tasks/tests.yml @@ -131,3 +131,41 @@ that: - change_existing_string_again is not changed - change_existing_string_again.value == "New Guest" + +- name: add policy setting + win_security_policy: + section: Privilege Rights + # following key is empty by default + key: SeCreateTokenPrivilege + # add Guests + value: '*S-1-5-32-546' + +- name: get actual policy setting + test_win_security_policy: + section: Privilege Rights + key: SeCreateTokenPrivilege + register: add_policy_setting_actual + +- name: assert remove policy setting + assert: + that: + - add_policy_setting_actual.value == '*S-1-5-32-546' + +- name: remove policy setting + win_security_policy: + section: Privilege Rights + key: SeCreateTokenPrivilege + value: '' + register: remove_policy_setting + +- name: get actual policy setting + test_win_security_policy: + section: Privilege Rights + key: SeCreateTokenPrivilege + register: remove_policy_setting_actual + +- name: assert remove policy setting + assert: + that: + - remove_policy_setting is changed + - remove_policy_setting_actual.value is none