mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
win_security_policy: Allow setting a value to empty (#42051)
* win_security_policy: allow removing values (resolves #40869) * Removing warning * Adding test for remove policy setting * Fixing string comparison * Make idempotent * Adding idempotency and diff test * added changelog fragment
This commit is contained in:
parent
b2527c55c3
commit
dc32842573
3 changed files with 59 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- win_security_policy - allows an empty string to reset a policy value https://github.com/ansible/ansible/issues/40869
|
|
@ -169,6 +169,8 @@ if ($secedit_ini.$section.ContainsKey($key)) {
|
||||||
$secedit_ini.$section.$key = $value
|
$secedit_ini.$section.$key = $value
|
||||||
$will_change = $true
|
$will_change = $true
|
||||||
}
|
}
|
||||||
|
} elseif ([string]$value -eq "") {
|
||||||
|
# Value is requested to be removed, and has already been removed, do nothing
|
||||||
} else {
|
} else {
|
||||||
if ($diff_mode) {
|
if ($diff_mode) {
|
||||||
$result.diff.prepared = @"
|
$result.diff.prepared = @"
|
||||||
|
@ -194,6 +196,8 @@ if ($will_change -eq $true) {
|
||||||
if ($new_value -cne $value) {
|
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"
|
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 {
|
} else {
|
||||||
Fail-Json $result "The key '$key' in section '$section' is not a valid key, cannot set this value"
|
Fail-Json $result "The key '$key' in section '$section' is not a valid key, cannot set this value"
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,3 +131,56 @@
|
||||||
that:
|
that:
|
||||||
- change_existing_string_again is not changed
|
- change_existing_string_again is not changed
|
||||||
- change_existing_string_again.value == "New Guest"
|
- 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 add 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: ''
|
||||||
|
diff: yes
|
||||||
|
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.diff.prepared == "[Privilege Rights]\n-SeCreateTokenPrivilege = *S-1-5-32-546\n+SeCreateTokenPrivilege = "
|
||||||
|
- remove_policy_setting_actual.value is none
|
||||||
|
|
||||||
|
- name: remove policy setting again
|
||||||
|
win_security_policy:
|
||||||
|
section: Privilege Rights
|
||||||
|
key: SeCreateTokenPrivilege
|
||||||
|
value: ''
|
||||||
|
register: remove_policy_setting_again
|
||||||
|
|
||||||
|
- name: assert remove policy setting again
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- remove_policy_setting_again is not changed
|
||||||
|
- remove_policy_setting_again.value == ''
|
||||||
|
|
Loading…
Reference in a new issue