mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Added win_reg_stat module (#19145)
This commit is contained in:
parent
2ac57e0bc3
commit
5cabe420ea
8 changed files with 616 additions and 0 deletions
1
test/integration/targets/win_reg_stat/aliases
Normal file
1
test/integration/targets/win_reg_stat/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
windows/ci/group1
|
24
test/integration/targets/win_reg_stat/files/test_reg.reg
Normal file
24
test/integration/targets/win_reg_stat/files/test_reg.reg
Normal file
|
@ -0,0 +1,24 @@
|
|||
Windows Registry Editor Version 5.00
|
||||
|
||||
[HKEY_CURRENT_USER\Test]
|
||||
|
||||
[HKEY_CURRENT_USER\Test\nested]
|
||||
"string"="test"
|
||||
"binary"=hex:01,16
|
||||
"dword"=dword:00000001
|
||||
"qword"=hex(b):01,00,00,00,00,00,00,00
|
||||
"multi"=hex(7):61,00,2c,00,20,00,62,00,00,00,63,00,00,00,00,00
|
||||
"expand"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,64,00,69,\
|
||||
00,72,00,00,00
|
||||
|
||||
[HKEY_CURRENT_USER\Test\nested\nest1]
|
||||
"dontcare"=""
|
||||
|
||||
[HKEY_CURRENT_USER\Test\nested\nest2]
|
||||
|
||||
|
||||
[HKEY_CURRENT_USER\Test\single]
|
||||
"string1"=""
|
||||
"string2"="abc123"
|
||||
"none"=hex(0):
|
||||
"none1"=hex(0):00
|
2
test/integration/targets/win_reg_stat/meta/main.yml
Normal file
2
test/integration/targets/win_reg_stat/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_win_tests
|
317
test/integration/targets/win_reg_stat/tasks/main.yml
Normal file
317
test/integration/targets/win_reg_stat/tasks/main.yml
Normal file
|
@ -0,0 +1,317 @@
|
|||
---
|
||||
- name: make sure win output dir exists
|
||||
win_file:
|
||||
path: "{{win_output_dir}}"
|
||||
state: directory
|
||||
|
||||
- name: template out test registry structure
|
||||
win_copy:
|
||||
src: test_reg.reg
|
||||
dest: "{{win_output_dir}}\\raw_test_reg.reg"
|
||||
|
||||
- name: convert the line endings to the windows variant
|
||||
win_shell: Get-Content "{{win_output_dir}}\raw_test_reg.reg" | Set-Content "{{win_output_dir}}\test_reg.reg"
|
||||
|
||||
- name: import test registry structure
|
||||
win_regmerge:
|
||||
path: "{{win_output_dir}}\\test_reg.reg"
|
||||
|
||||
- name: get value of expand string %windir%
|
||||
win_command: powershell.exe $env:windir
|
||||
register: win_dir_value
|
||||
|
||||
- name: expect failure when not passing in key option
|
||||
win_reg_stat:
|
||||
property: a
|
||||
register: actual
|
||||
failed_when: "actual.msg != 'Missing required argument: key'"
|
||||
|
||||
- name: expect failure when passing in an invalid hive
|
||||
win_reg_stat:
|
||||
key: ABCD:\test
|
||||
register: actual
|
||||
failed_when: actual.msg != "the hive in key is 'ABCD'; must be 'HKCR', 'HKCC', 'HKCU', 'HKLM' or 'HKU'"
|
||||
|
||||
- name: get known nested reg key structure for testing with short hive form
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\nested
|
||||
register: actual_short
|
||||
|
||||
- name: get known nested reg key structure for testing with quoted yaml
|
||||
win_reg_stat:
|
||||
key: "HKCU:\\Test\\nested"
|
||||
register: actual_quoted
|
||||
|
||||
- name: set expected value for reg structure
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
properties:
|
||||
binary: { raw_value: ["0x01", "0x16"], type: 'REG_BINARY', value: [1, 22] }
|
||||
dword: { raw_value: 1, type: 'REG_DWORD', value: 1 }
|
||||
expand: { raw_value: '%windir%\dir', type: 'REG_EXPAND_SZ', value: "{{win_dir_value.stdout_lines[0]}}\\dir" }
|
||||
multi: { raw_value: ['a, b', 'c'], type: 'REG_MULTI_SZ', value: ['a, b', 'c'] }
|
||||
qword: { raw_value: 1, type: 'REG_QWORD', value: 1 }
|
||||
string: { raw_value: 'test', type: 'REG_SZ', value: 'test' }
|
||||
sub_keys:
|
||||
- nest1
|
||||
- nest2
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual_short == expected"
|
||||
- "actual_quoted == expected"
|
||||
|
||||
- name: get known reg key with no sub keys but some properties
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\single
|
||||
register: actual
|
||||
|
||||
- name: set expected value for reg key with no sub keys but some properties
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
properties:
|
||||
none: { raw_value: [], type: 'REG_NONE', value: [] }
|
||||
none1: { raw_value: ["0x00"], type: 'REG_NONE', value: [0] }
|
||||
string1: { raw_value: '', type: 'REG_SZ', value: '' }
|
||||
string2: { raw_value: 'abc123', type: 'REG_SZ', value: 'abc123' }
|
||||
sub_keys: []
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get known reg key without sub keys and properties
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\nested\nest2
|
||||
register: actual
|
||||
|
||||
- name: set expected value for reg key without sub keys or properties
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
properties: {}
|
||||
sub_keys: []
|
||||
register: expected
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get non-existant reg key
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\Thispathwillneverexist
|
||||
register: actual
|
||||
|
||||
- name: set expected value for non-existant reg key
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: false
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get string property
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\nested
|
||||
property: string
|
||||
register: actual
|
||||
|
||||
- name: set expected string property
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
raw_value: 'test'
|
||||
type: 'REG_SZ'
|
||||
value: 'test'
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get expand string property
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\nested
|
||||
property: expand
|
||||
register: actual
|
||||
|
||||
- name: set expected expand string property
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
raw_value: '%windir%\dir'
|
||||
type: 'REG_EXPAND_SZ'
|
||||
value: "{{win_dir_value.stdout_lines[0]}}\\dir"
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get multi string property
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\nested
|
||||
property: multi
|
||||
register: actual
|
||||
|
||||
- name: set expected multi string property
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
raw_value: ['a, b', 'c']
|
||||
type: 'REG_MULTI_SZ'
|
||||
value: ['a, b', 'c']
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get binary property
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\nested
|
||||
property: binary
|
||||
register: actual
|
||||
|
||||
- name: set expected binary property
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
raw_value: ["0x01", "0x16"]
|
||||
type: 'REG_BINARY'
|
||||
value: [1, 22]
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get dword property
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\nested
|
||||
property: dword
|
||||
register: actual
|
||||
|
||||
- name: set expected dword property
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
raw_value: 1
|
||||
type: 'REG_DWORD'
|
||||
value: 1
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get qword property
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\nested
|
||||
property: qword
|
||||
register: actual
|
||||
|
||||
- name: set expected qword property
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
raw_value: 1
|
||||
type: 'REG_QWORD'
|
||||
value: 1
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get none property
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\single
|
||||
property: none
|
||||
register: actual
|
||||
|
||||
- name: set expected none property
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
raw_value: []
|
||||
type: 'REG_NONE'
|
||||
value: []
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get none with value property
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\single
|
||||
property: none1
|
||||
register: actual
|
||||
|
||||
- name: set expected none with value property
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: true
|
||||
raw_value: ["0x00"]
|
||||
type: 'REG_NONE'
|
||||
value: [0]
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: get non-existance property
|
||||
win_reg_stat:
|
||||
key: HKCU:\Test\single
|
||||
property: doesnotexist
|
||||
register: actual
|
||||
|
||||
- name: set expected non-existance property
|
||||
set_fact:
|
||||
expected:
|
||||
changed: false
|
||||
win_reg_stat:
|
||||
exists: false
|
||||
|
||||
- name: validate test
|
||||
assert:
|
||||
that:
|
||||
- "actual == expected"
|
||||
|
||||
- name: remove registry entry
|
||||
win_regedit:
|
||||
key: HKCU:\Test
|
||||
state: absent
|
|
@ -7,3 +7,4 @@
|
|||
- { role: win_async_wrapper, tags: ["test_win_async_wrapper", "test_async_wrapper", "test_win_async_status", "test_async_status"] }
|
||||
- { role: win_shell, tags: test_win_shell }
|
||||
- { role: win_command, tags: test_win_command }
|
||||
- { role: win_reg_stat, tags: test_win_reg_stat }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue