1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
---
- name: expect failure when not passing in path option
win_reg_stat:
name: a
register: actual
failed_when: "actual.msg != 'Get-AnsibleParam: Missing required argument: path'"
- name: expect failure when passing in an invalid hive
win_reg_stat:
path: ABCD:\test
register: actual
failed_when: 'actual.msg != "path: ABCD:\\test is not a valid registry path, see module documentation for examples."'
- name: get known nested reg key structure
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\nested
register: actual
- name: set expected value for reg structure
set_fact:
expected:
changed: false
exists: true
failed: false
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" }
large_dword: { raw_value: 4294967295, type: 'REG_DWORD', value: 4294967295 }
large_qword: { raw_value: 18446744073709551615, type: 'REG_QWORD', value: 18446744073709551615 }
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: assert get known nested reg key structure
assert:
that:
- actual == expected
- name: get known reg key with no sub keys but some properties
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\single
register: actual
- name: set expected value for reg key with no sub keys but some properties
set_fact:
expected:
changed: false
exists: true
failed: false
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: assert get known reg key with no sub keys but some properties
assert:
that:
- actual == expected
- name: get known reg key without sub keys and properties
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\nested\nest2
register: actual
- name: set expected value for reg key without sub keys or properties
set_fact:
expected:
changed: false
exists: true
failed: false
properties: {}
sub_keys: []
register: expected
- name: assert get known reg key without sub keys and properties
assert:
that:
- actual == expected
- name: get non-existent reg key
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\Thispathwillneverexist
register: actual
- name: set expected value for non-existent reg key
set_fact:
expected:
changed: false
exists: false
failed: false
- name: assert get non-existent reg key
assert:
that:
- actual == expected
- name: get string property
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\nested
name: string
register: actual
- name: set expected string property
set_fact:
expected:
changed: false
exists: true
failed: false
raw_value: 'test'
type: 'REG_SZ'
value: 'test'
- name: assert get string property
assert:
that:
- actual == expected
- name: get expand string property
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\nested
name: expand
register: actual
- name: set expected expand string property
set_fact:
expected:
changed: false
exists: true
failed: false
raw_value: '%windir%\dir'
type: 'REG_EXPAND_SZ'
value: "{{win_dir_value.stdout_lines[0]}}\\dir"
- name: assert get expand string property
assert:
that:
- actual == expected
- name: get multi string property
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\nested
name: multi
register: actual
- name: set expected multi string property
set_fact:
expected:
changed: false
exists: true
failed: false
raw_value: ['a, b', 'c']
type: 'REG_MULTI_SZ'
value: ['a, b', 'c']
- name: assert get multi string property
assert:
that:
- actual == expected
- name: get binary property
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\nested
name: binary
register: actual
- name: set expected binary property
set_fact:
expected:
changed: false
exists: true
failed: false
raw_value: ["0x01", "0x16"]
type: 'REG_BINARY'
value: [1, 22]
- name: assert get binary property
assert:
that:
- actual == expected
- name: get dword property
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\nested
name: dword
register: actual
- name: set expected dword property
set_fact:
expected:
changed: false
exists: true
failed: false
raw_value: 1
type: 'REG_DWORD'
value: 1
- name: assert get dword property
assert:
that:
- actual == expected
- name: get qword property
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\nested
name: qword
register: actual
- name: set expected qword property
set_fact:
expected:
changed: false
exists: true
failed: false
raw_value: 1
type: 'REG_QWORD'
value: 1
- name: assert get qword property
assert:
that:
- actual == expected
- name: get none property
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\single
name: none
register: actual
- name: set expected none property
set_fact:
expected:
changed: false
exists: true
failed: false
raw_value: []
type: 'REG_NONE'
value: []
- name: assert get none property
assert:
that:
- actual == expected
- name: get none with value property
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\single
name: none1
register: actual
- name: set expected none with value property
set_fact:
expected:
changed: false
exists: true
failed: false
raw_value: ["0x00"]
type: 'REG_NONE'
value: [0]
- name: assert get non with value property
assert:
that:
- actual == expected
- name: get non-existent property
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\single
name: doesnotexist
register: actual
- name: set expected non-existent property
set_fact:
expected:
changed: false
exists: false
failed: false
- name: assert get non-existent property
assert:
that:
- actual == expected
- name: get key with default property set
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\Duplicate Default
register: actual
- name: assert get key with default property set
assert:
that:
- actual.properties[""]['raw_value'] == "default"
- actual.properties[""]['type'] == "REG_SZ"
- actual.properties[""]['value'] == "default"
- actual.properties['(Default)'].raw_value == "custom"
- actual.properties['(Default)'].type == "REG_SZ"
- actual.properties['(Default)'].value == "custom"
- name: get default property
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\Duplicate Default
name: ''
register: actual
- name: assert get default property
assert:
that:
- actual.value == "default"
- actual.raw_value == "default"
- actual.type == "REG_SZ"
- name: get key with blank property set
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\Blank Default
register: actual
- name: assert get key with blank property set
assert:
that:
- actual.properties[""].raw_value == ""
- actual.properties[""].type == "REG_SZ"
- actual.properties[""].value == ""
- actual.properties['(Default)'].raw_value == ""
- actual.properties['(Default)'].type == "REG_SZ"
- actual.properties['(Default)'].value == ""
- name: get default property as empty string
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\Blank Default
name: ''
register: actual
- name: assert get default property as empty string
assert:
that:
- actual.value == ""
- actual.raw_value == ""
- actual.type == "REG_SZ"
- name: get key with no properties set
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\Empty Default
register: actual
- name: assert get key with no properties set
assert:
that:
- actual.properties == {}
- name: get default property that has not been set
win_reg_stat:
path: HKCU:\{{ test_reg_path }}\Empty Default
name: ''
register: actual
- name: assert get default property that has not been set
assert:
that:
- not actual.exists
|