win_regedit: added function to load a dat file for editing (#31289)

* win_regedit: added function to load a dat file for editing

* try to make the tests more resiliant

* more stability changes
This commit is contained in:
Jordan Borean 2017-10-18 06:30:33 +10:00 committed by GitHub
commit 743ff4897a
6 changed files with 597 additions and 129 deletions

View file

@ -1,2 +1,3 @@
test_win_regedit_local_key: HKLM:\Software\Cow Corp
test_win_regedit_classes_key: HKCR:\.test-ansible
test_win_regedit_hive_key: HKLM:\ANSIBLE\NewKey

View file

@ -0,0 +1,18 @@
---
- name: load HKLM:\ANSIBLE with test hive
win_command: reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat
failed_when: false
- name: make sure testing keys are removed before test
win_regedit:
path: '{{item}}'
delete_key: yes
state: absent
with_items:
- '{{test_win_regedit_local_key}}'
- '{{test_win_regedit_classes_key}}'
- '{{test_win_regedit_hive_key}}'
- name: ensure HKLM:\ANSIBLE is unloaded
win_command: reg.exe unload HKLM\ANSIBLE
failed_when: false

View file

@ -1,12 +1,6 @@
---
- name: make sure testing keys are removed before test
win_regedit:
path: '{{item}}'
delete_key: yes
state: absent
with_items:
- '{{test_win_regedit_local_key}}'
- '{{test_win_regedit_classes_key}}'
- name: make sure we start on a blank state
include_tasks: cleanup.yml
- block:
- name: run tests for each property type
@ -81,10 +75,4 @@
always:
- name: make sure testing keys are removed after test
win_regedit:
path: '{{item}}'
delete_key: yes
state: absent
with_items:
- '{{test_win_regedit_local_key}}'
- '{{test_win_regedit_classes_key}}'
include_tasks: cleanup.yml

View file

@ -458,3 +458,258 @@
assert:
that:
- not create_prop_with_json_again|changed
- name: create new key in loaded hive (check mode)
win_regedit:
path: '{{test_win_regedit_hive_key}}'
state: present
hive: C:\Users\Default\NTUSER.dat
register: new_key_in_hive_check
check_mode: yes
- name: get result of create new key in loaded hive (check mode)
win_shell: |
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
Test-Path -Path HKLM:\ANSIBLE\NewKey
exit 0
register: new_key_in_hive_result_check
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of create new key in loaded hive (check mode)
assert:
that:
- new_key_in_hive_check|changed
- new_key_in_hive_result_check.stdout == "False\r\n"
- name: create new key in loaded hive
win_regedit:
path: '{{test_win_regedit_hive_key}}'
state: present
hive: C:\Users\Default\NTUSER.dat
register: new_key_in_hive
- name: get result of create new key in loaded hive
win_shell: |
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
Test-Path -Path HKLM:\ANSIBLE\NewKey
exit 0
register: new_key_in_hive_result
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of create new key in loaded hive
assert:
that:
- new_key_in_hive|changed
- new_key_in_hive_result.stdout == "True\r\n"
- name: create new key in loaded hive (idempotent)
win_regedit:
path: '{{test_win_regedit_hive_key}}'
state: present
hive: C:\Users\Default\NTUSER.dat
register: new_key_in_hive_again
- name: assert result of create new key in loaded hive (idempotent)
assert:
that:
- not new_key_in_hive_again|changed
- name: set hive key property (check mode)
win_regedit:
path: '{{test_win_regedit_hive_key}}'
name: TestProp
data: string
type: string
state: present
hive: C:\Users\Default\NTUSER.dat
register: new_prop_in_hive_check
check_mode: yes
- name: get result of set hive key property (check mode)
win_shell: |
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
if ($prop) {
$prop.TestProp
}
exit 0
register: new_prop_in_hive_result_check
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of set hive key property (check mode)
assert:
that:
- new_prop_in_hive_check|changed
- new_prop_in_hive_result_check.stdout == ""
- name: set hive key property
win_regedit:
path: '{{test_win_regedit_hive_key}}'
name: TestProp
data: string
type: string
state: present
hive: C:\Users\Default\NTUSER.dat
register: new_prop_in_hive
- name: get result of set hive key property
win_shell: |
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
if ($prop) {
$prop.TestProp
}
exit 0
register: new_prop_in_hive_result
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of set hive key property
assert:
that:
- new_prop_in_hive|changed
- new_prop_in_hive_result.stdout == "string\r\n"
- name: set hive key property (idempotent)
win_regedit:
path: '{{test_win_regedit_hive_key}}'
name: TestProp
data: string
type: string
state: present
hive: C:\Users\Default\NTUSER.dat
register: new_prop_in_hive_again
- name: assert result of set hive key property (idempotent)
assert:
that:
- not new_prop_in_hive_again|changed
- name: remove hive key property (check mode)
win_regedit:
path: '{{test_win_regedit_hive_key}}'
name: TestProp
state: absent
hive: C:\Users\Default\NTUSER.dat
register: remove_prop_in_hive_check
check_mode: yes
- name: get result of remove hive key property (check mode)
win_shell: |
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
if ($prop) {
$prop.TestProp
}
exit 0
register: remove_prop_in_hive_result_check
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of remove hive key property (check mode)
assert:
that:
- remove_prop_in_hive_check|changed
- remove_prop_in_hive_result_check.stdout == "string\r\n"
- name: remove hive key property
win_regedit:
path: '{{test_win_regedit_hive_key}}'
name: TestProp
state: absent
hive: C:\Users\Default\NTUSER.dat
register: remove_prop_in_hive
- name: get result of remove hive key property
win_shell: |
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
if ($prop) {
$prop.TestProp
}
exit 0
register: remove_prop_in_hive_result
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of remove hive key property
assert:
that:
- remove_prop_in_hive|changed
- remove_prop_in_hive_result.stdout == ""
- name: remove hive key property (idempotent)
win_regedit:
path: '{{test_win_regedit_hive_key}}'
name: TestProp
state: absent
hive: C:\Users\Default\NTUSER.dat
register: remove_prop_in_hive_again
- name: assert result of set hive key property (idempotent)
assert:
that:
- not remove_prop_in_hive_again|changed
- name: remove key in loaded hive (check mode)
win_regedit:
path: '{{test_win_regedit_hive_key}}'
state: absent
delete_yes: yes
hive: C:\Users\Default\NTUSER.dat
register: remove_key_in_hive_check
check_mode: yes
- name: get result of remove key in loaded hive (check mode)
win_shell: |
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
Test-Path -Path HKLM:\ANSIBLE\NewKey
exit 0
register: remove_key_in_hive_result_check
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of removekey in loaded hive (check mode)
assert:
that:
- remove_key_in_hive_check|changed
- remove_key_in_hive_result_check.stdout == "True\r\n"
- name: remove key in loaded hive
win_regedit:
path: '{{test_win_regedit_hive_key}}'
state: absent
delete_yes: yes
hive: C:\Users\Default\NTUSER.dat
register: remove_key_in_hive
- name: get result of remove key in loaded hive
win_shell: |
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
Test-Path -Path HKLM:\ANSIBLE\NewKey
exit 0
register: remove_key_in_hive_result
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of remove key in loaded hive
assert:
that:
- remove_key_in_hive|changed
- remove_key_in_hive_result.stdout == "False\r\n"
- name: remove key in loaded hive (idempotent)
win_regedit:
path: '{{test_win_regedit_hive_key}}'
state: absent
delete_yes: yes
hive: C:\Users\Default\NTUSER.dat
register: remove_key_in_hive_again
- name: assert result of remove key in loaded hive (idempotent)
assert:
that:
- not remove_key_in_hive_again|changed