mirror of https://github.com/ansible/ansible.git
win_regedit: rewrite to support edge cases and fix issues (#26468)
* win_regedit: rewrite to support edge cases and fix issues * fix up byte handling of single bytes and minor doc fix * removed unused method * updated with requested changespull/26817/head
parent
080e9ee694
commit
eb1ed6567c
@ -0,0 +1,2 @@
|
||||
test_win_regedit_local_key: HKLM:\Software\Cow Corp
|
||||
test_win_regedit_classes_key: HKCR:\.test-ansible
|
@ -1,2 +0,0 @@
|
||||
dependencies:
|
||||
- prepare_win_tests
|
@ -0,0 +1,236 @@
|
||||
# repeatable tests for each key type
|
||||
# takes in the following variables
|
||||
# test_win_regedit_key_type: the type of key
|
||||
# test_win_regedit_key_expected_type: the expected key type
|
||||
# test_win_regedit_key_data1: the data to create first
|
||||
# test_win_regedit_key_data2: the data to change tp
|
||||
# test_win_regedit_key_expected_value_null: the expected value for a null key
|
||||
# test_win_regedit_key_expected_value1: the expected value for the data1
|
||||
# test_win_regedit_key_expected_value2: the expected value for the data2
|
||||
---
|
||||
- name: create a null {{test_win_regedit_key_type}} check
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: empty_{{test_win_regedit_key_type}}
|
||||
type: '{{test_win_regedit_key_type}}'
|
||||
state: present
|
||||
register: null_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual on null {{test_win_regedit_key_type}} check
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: empty_{{test_win_regedit_key_type}}
|
||||
register: null_actual_check
|
||||
|
||||
- name: assert create a null {{test_win_regedit_key_type}} check
|
||||
assert:
|
||||
that:
|
||||
- null_check|changed
|
||||
- null_check.data_changed == False
|
||||
- null_check.data_type_changed == False
|
||||
- null_actual_check.exists == False
|
||||
|
||||
- name: create a null {{test_win_regedit_key_type}}
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: empty_{{test_win_regedit_key_type}}
|
||||
type: '{{test_win_regedit_key_type}}'
|
||||
state: present
|
||||
register: null_create
|
||||
|
||||
- name: get actual on null {{test_win_regedit_key_type}}
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: empty_{{test_win_regedit_key_type}}
|
||||
register: null_create_actual
|
||||
|
||||
- name: assert create a null {{test_win_regedit_key_type}}
|
||||
assert:
|
||||
that:
|
||||
- null_create|changed
|
||||
- null_create.data_changed == False
|
||||
- null_create.data_type_changed == False
|
||||
- null_create_actual.exists == True
|
||||
- null_create_actual.raw_value == test_win_regedit_key_expected_value_null
|
||||
- null_create_actual.type == test_win_regedit_key_expected_type
|
||||
when: test_win_regedit_key_type not in ['dword', 'qword']
|
||||
|
||||
# dword and qword are different, need to convert the expected value null to an int
|
||||
- name: assert create a null {{test_win_regedit_key_type}} for dword and qword
|
||||
assert:
|
||||
that:
|
||||
- null_create|changed
|
||||
- null_create.data_changed == False
|
||||
- null_create.data_type_changed == False
|
||||
- null_create_actual.exists == True
|
||||
- null_create_actual.raw_value == test_win_regedit_key_expected_value_null|int
|
||||
- null_create_actual.type == test_win_regedit_key_expected_type
|
||||
when: test_win_regedit_key_type in ['dword', 'qword']
|
||||
|
||||
- name: create a null {{test_win_regedit_key_type}} again
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: empty_{{test_win_regedit_key_type}}
|
||||
type: '{{test_win_regedit_key_type}}'
|
||||
state: present
|
||||
register: null_create_again
|
||||
|
||||
- name: assert create a null {{test_win_regedit_key_type}} again
|
||||
assert:
|
||||
that:
|
||||
- not null_create_again|changed
|
||||
|
||||
- name: create a {{test_win_regedit_key_type}} check
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_{{test_win_regedit_key_type}}
|
||||
data: '{{test_win_regedit_key_data1}}'
|
||||
type: '{{test_win_regedit_key_type}}'
|
||||
state: present
|
||||
register: data_create_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual on {{test_win_regedit_key_type}} check
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_{{test_win_regedit_key_type}}
|
||||
register: data_create_actual_check
|
||||
|
||||
- name: assert create a {{test_win_regedit_key_type}} check
|
||||
assert:
|
||||
that:
|
||||
- data_create_check|changed
|
||||
- data_create_check.data_changed == False
|
||||
- data_create_check.data_type_changed == False
|
||||
- data_create_actual_check.exists == False
|
||||
|
||||
- name: create a {{test_win_regedit_key_type}}
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_{{test_win_regedit_key_type}}
|
||||
data: '{{test_win_regedit_key_data1}}'
|
||||
type: '{{test_win_regedit_key_type}}'
|
||||
state: present
|
||||
register: data_create
|
||||
|
||||
- name: get actual on {{test_win_regedit_key_type}}
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_{{test_win_regedit_key_type}}
|
||||
register: data_create_actual
|
||||
|
||||
- name: assert create a {{test_win_regedit_key_type}}
|
||||
assert:
|
||||
that:
|
||||
- data_create|changed
|
||||
- data_create.data_changed == False
|
||||
- data_create.data_type_changed == False
|
||||
- data_create_actual.exists == True
|
||||
- data_create_actual.raw_value == test_win_regedit_key_expected_value1
|
||||
- data_create_actual.type == test_win_regedit_key_expected_type
|
||||
when: test_win_regedit_key_type not in ['dword', 'qword']
|
||||
|
||||
- name: debug 1
|
||||
debug:
|
||||
var: test_win_regedit_key_expected_value1
|
||||
|
||||
- name: debug 2
|
||||
debug:
|
||||
var: test_win_regedit_key_expected_value1|int
|
||||
|
||||
- name: assert create a {{test_win_regedit_key_type}} for dword or qword
|
||||
assert:
|
||||
that:
|
||||
- data_create|changed
|
||||
- data_create.data_changed == False
|
||||
- data_create.data_type_changed == False
|
||||
- data_create_actual.exists == True
|
||||
- data_create_actual.raw_value == test_win_regedit_key_expected_value1|int
|
||||
- data_create_actual.type == test_win_regedit_key_expected_type
|
||||
when: test_win_regedit_key_type in ['dword', 'qword']
|
||||
|
||||
- name: create a {{test_win_regedit_key_type}} again
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_{{test_win_regedit_key_type}}
|
||||
data: '{{test_win_regedit_key_data1}}'
|
||||
type: '{{test_win_regedit_key_type}}'
|
||||
state: present
|
||||
register: data_create_again
|
||||
|
||||
- name: assert create a {{test_win_regedit_key_type}} again
|
||||
assert:
|
||||
that:
|
||||
- not data_create_again|changed
|
||||
|
||||
- name: change existing {{test_win_regedit_key_type}} data check
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_{{test_win_regedit_key_type}}
|
||||
data: '{{test_win_regedit_key_data2}}'
|
||||
type: '{{test_win_regedit_key_type}}'
|
||||
state: present
|
||||
register: change_data_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual of change existing {{test_win_regedit_key_type}} data check
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_{{test_win_regedit_key_type}}
|
||||
register: change_data_actual_check
|
||||
|
||||
- name: assert change existing {{test_win_regedit_key_type}} data check
|
||||
assert:
|
||||
that:
|
||||
- change_data_check|changed
|
||||
- change_data_check.data_changed == True
|
||||
- change_data_check.data_type_changed == False
|
||||
- change_data_actual_check == data_create_actual
|
||||
|
||||
- name: change existing {{test_win_regedit_key_type}} data
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_{{test_win_regedit_key_type}}
|
||||
data: '{{test_win_regedit_key_data2}}'
|
||||
type: '{{test_win_regedit_key_type}}'
|
||||
state: present
|
||||
register: change_data
|
||||
|
||||
- name: get actual of change existing {{test_win_regedit_key_type}} data
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_{{test_win_regedit_key_type}}
|
||||
register: change_data_actual
|
||||
|
||||
- name: assert change existing {{test_win_regedit_key_type}} data
|
||||
assert:
|
||||
that:
|
||||
- change_data|changed
|
||||
- change_data.data_changed == True
|
||||
- change_data.data_type_changed == False
|
||||
- change_data_actual.raw_value == test_win_regedit_key_expected_value2
|
||||
when: test_win_regedit_key_type not in ['dword', 'qword']
|
||||
|
||||
- name: assert change existing {{test_win_regedit_key_type}} data for dword or qword
|
||||
assert:
|
||||
that:
|
||||
- change_data|changed
|
||||
- change_data.data_changed == True
|
||||
- change_data.data_type_changed == False
|
||||
- change_data_actual.raw_value == test_win_regedit_key_expected_value2|int
|
||||
when: test_win_regedit_key_type in ['dword', 'qword']
|
||||
|
||||
- name: change existing {{test_win_regedit_key_type}} data again
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_{{test_win_regedit_key_type}}
|
||||
data: '{{test_win_regedit_key_data2}}'
|
||||
type: '{{test_win_regedit_key_type}}'
|
||||
state: present
|
||||
register: change_data_again
|
||||
|
||||
- name: assert change existing {{test_win_regedit_key_type}} data again
|
||||
assert:
|
||||
that:
|
||||
- not change_data_again|changed
|
@ -1,473 +1,93 @@
|
||||
# test code for the win_regedit module
|
||||
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# clear the area of the registry we are using for tests
|
||||
|
||||
# test mangled registry key gets caught following https://github.com/ansible/ansible-modules-extras/issues/2412
|
||||
|
||||
- name: test mangled registry key is caught (avoids bizare error message from powershell)
|
||||
win_regedit:
|
||||
key: HKCU\Software
|
||||
value: invalid_key
|
||||
data: invalid_key
|
||||
datatype: string
|
||||
register: check00_result
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check00_result.failed == true"
|
||||
- "check00_result.msg == 'path: HKCU\\Software is not a valid powershell path, see module documentation for examples.'"
|
||||
|
||||
- name: remove setting
|
||||
win_regedit:
|
||||
key: 'HKCU:\SOFTWARE\Cow Corp'
|
||||
state: absent
|
||||
|
||||
- name: check basic set works
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hello
|
||||
data: world
|
||||
register: check01_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check01_result.changed == true"
|
||||
|
||||
- name: check that setting the same again is not changed
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hello
|
||||
data: world
|
||||
register: check02_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check02_result.changed == false"
|
||||
|
||||
# binary mode checks
|
||||
# tests with 'hex:' prefix (as intended)
|
||||
|
||||
- name: check binary with hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be,ef,be,ef,be,ef,be,ef,be,ef
|
||||
datatype: binary
|
||||
register: check03_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check03_result.changed == true"
|
||||
|
||||
- name: check binary with hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be,ef,be,ef,be,ef,be,ef,be,ef
|
||||
datatype: binary
|
||||
register: check04_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check04_result.changed == false"
|
||||
|
||||
- name: check binary with hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:de,ad,be,ef,de,ad,be,ef,de,ad,be,ef
|
||||
datatype: binary
|
||||
register: check05_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check05_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check06_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check06_result.changed == true"
|
||||
|
||||
# check without hex(colon) prefix
|
||||
|
||||
# tests without 'hex:' prefix (optional)
|
||||
- name: check binary with hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be,ef,be,ef,be,ef,be,ef,be,ef
|
||||
datatype: binary
|
||||
register: check13_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check13_result.changed == true"
|
||||
|
||||
- name: check binary without hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be,ef,be,ef,be,ef,be,ef,be,ef
|
||||
datatype: binary
|
||||
register: check14_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check14_result.changed == false"
|
||||
|
||||
- name: check binary without hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: de,ad,be,ef,de,ad,be,ef,de,ad,be,ef
|
||||
datatype: binary
|
||||
register: check15_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check15_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check16_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check16_result.changed == true"
|
||||
|
||||
# check mixed case hex values with hex: prefix
|
||||
|
||||
- name: check mixed case binary with hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be,EF,be,EF,be,EF,be,EF,be,EF
|
||||
datatype: binary
|
||||
register: check23_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check23_result.changed == true"
|
||||
|
||||
- name: check mixed case binary with hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be,EF,be,EF,be,EF,be,EF,be,EF
|
||||
datatype: binary
|
||||
register: check24_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check24_result.changed == false"
|
||||
|
||||
- name: check mixed case binary with hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:DE,ad,be,EF,DE,ad,be,EF,DE,ad,be,EF
|
||||
datatype: binary
|
||||
register: check25_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check25_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check26_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check26_result.changed == true"
|
||||
|
||||
# check mixed case without hex: prefix
|
||||
|
||||
# tests without 'hex:' prefix (optional)
|
||||
- name: check mixed case binary without hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be,EF,be,EF,be,EF,be,EF,be,EF
|
||||
datatype: binary
|
||||
register: check33_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check33_result.changed == true"
|
||||
|
||||
- name: check mixed case binary without hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be,EF,be,EF,be,EF,be,EF,be,EF
|
||||
datatype: binary
|
||||
register: check34_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check34_result.changed == false"
|
||||
|
||||
- name: check mixed case binary without hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: DE,ad,be,EF,DE,ad,be,EF,DE,ad,be,EF
|
||||
datatype: binary
|
||||
register: check35_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check35_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check36_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check36_result.changed == true"
|
||||
|
||||
# check colon separated hex values with hex: prefix
|
||||
|
||||
- name: check colon separated hex values with hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be:ef:be:ef:be:ef:be:ef:be:ef
|
||||
datatype: binary
|
||||
register: check43_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check43_result.changed == true"
|
||||
|
||||
- name: check colon separated binary with hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be:ef:be:ef:be:ef:be:ef:be:ef
|
||||
datatype: binary
|
||||
register: check44_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check44_result.changed == false"
|
||||
|
||||
- name: check colon separated binary with hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef
|
||||
datatype: binary
|
||||
register: check45_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check45_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check46_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check46_result.changed == true"
|
||||
|
||||
# check colon separated hex values without hex(colon) prefix
|
||||
|
||||
# tests without 'hex:' prefix (optional)
|
||||
- name: check colon separated binary with hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be:ef:be:ef:be:ef:be:ef:be:ef
|
||||
datatype: binary
|
||||
register: check53_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check53_result.changed == true"
|
||||
|
||||
- name: check colon separated binary without hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be:ef:be:ef:be:ef:be:ef:be:ef
|
||||
datatype: binary
|
||||
register: check54_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check54_result.changed == false"
|
||||
|
||||
- name: check colon separated binary without hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: de:ad:be:ef:de:ad:be:ef:de:ad:be:ef
|
||||
datatype: binary
|
||||
register: check55_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check55_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
---
|
||||
- name: make sure testing keys are removed before test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
path: '{{item}}'
|
||||
delete_key: yes
|
||||
state: absent
|
||||
register: check56_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check56_result.changed == true"
|
||||
|
||||
# test empty data value (some things depend on this, having no data is not equivalent)
|
||||
|
||||
- name: set an empty data value
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: helloempty
|
||||
data: ""
|
||||
register: check61_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check61_result.changed == true"
|
||||
|
||||
- name: set an empty data value again (should not change)
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: helloempty
|
||||
data: ""
|
||||
register: check62_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check62_result.changed == false"
|
||||
|
||||
# check can use yaml array of bytes as input
|
||||
- name: regedit binary data using yaml syntax
|
||||
win_regedit:
|
||||
key: 'HKCU:\SOFTWARE\Cow Corp'
|
||||
value: hellobinaryfromyaml
|
||||
data: [0x21, 0xb3, 0x33, 0xf9, 0x0d, 0xff, 0xd0, 0x01]
|
||||
datatype: binary
|
||||
register: check63_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check63_result.changed == true"
|
||||
|
||||
- name: regedit binary data using yaml syntax again
|
||||
win_regedit:
|
||||
key: 'HKCU:\SOFTWARE\Cow Corp'
|
||||
value: hellobinaryfromyaml
|
||||
data: [0x21, 0xb3, 0x33, 0xf9, 0x0d, 0xff, 0xd0, 0x01]
|
||||
datatype: binary
|
||||
register: check64_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check64_result.changed == false"
|
||||
|
||||
# test dword
|
||||
|
||||
- name: check basic set dword works
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hello_dword
|
||||
data: 00000000
|
||||
datatype: dword
|
||||
register: check71_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check71_result.changed == true"
|
||||
|
||||
- name: check that setting the same dword again is not changed
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hello_dword
|
||||
data: 00000000
|
||||
datatype: dword
|
||||
register: check72_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check72_result.changed == false"
|
||||
|
||||
# https://github.com/ansible/ansible/issues/26049
|
||||
# module reports change on dword with hex value even with same value
|
||||
- name: create hex value with prepending 0x
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: full_hex_dword
|
||||
data: 0xffffffff
|
||||
datatype: dword
|
||||
register: dword_create
|
||||
|
||||
- name: change hex value and report no changes
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: full_hex_dword
|
||||
data: 0xffffffff
|
||||
datatype: dword
|
||||
register: dword_create_again
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not dword_create_again|changed
|
||||
|
||||
# tear down
|
||||
|
||||
- name: remove registry key used for testing
|
||||
win_regedit:
|
||||
key: 'HKCU:\SOFTWARE\Cow Corp'
|
||||
state: absent
|
||||
|
||||
|
||||
# END OF win_regedit tests
|
||||
with_items:
|
||||
- '{{test_win_regedit_local_key}}'
|
||||
- '{{test_win_regedit_classes_key}}'
|
||||
|
||||
- block:
|
||||
- name: run old tests for PR only
|
||||
include_tasks: old_tests.yml
|
||||
|
||||
- name: run tests for each property type
|
||||
include_tasks: create_tests.yml
|
||||
vars:
|
||||
test_win_regedit_key_type: '{{item.type}}'
|
||||
test_win_regedit_key_expected_type: '{{item.reg_type}}'
|
||||
test_win_regedit_key_data1: '{{item.data1}}'
|
||||
test_win_regedit_key_data2: '{{item.data2}}'
|
||||
test_win_regedit_key_expected_value_null: '{{item.value_null}}'
|
||||
test_win_regedit_key_expected_value1: '{{item.value1}}'
|
||||
test_win_regedit_key_expected_value2: '{{item.value2}}'
|
||||
items:
|
||||
- type: dword
|
||||
reg_type: REG_DWORD
|
||||
data1: 1337 # decimal format
|
||||
data2: 0xffffffff # hex format and larger number
|
||||
value_null: 0
|
||||
value1: 1337
|
||||
value2: 4294967295
|
||||
|
||||
- type: qword
|
||||
reg_type: REG_QWORD
|
||||
data1: 18446744073709551615 # larger decimal format
|
||||
data2: 0x1ffffffff # hex format and larger number
|
||||
value_null: 0
|
||||
value1: 18446744073709551615
|
||||
value2: 8589934591
|
||||
|
||||
- type: string
|
||||
reg_type: REG_SZ
|
||||
data1: hello world
|
||||
data2: new hello world
|
||||
value_null: ""
|
||||
value1: hello world
|
||||
value2: new hello world
|
||||
|
||||
- type: expandstring
|
||||
reg_type: REG_EXPAND_SZ
|
||||
data1: '%windir%\test'
|
||||
data2: '%AppData%\local'
|
||||
value_null: ""
|
||||
value1: '%windir%\test'
|
||||
value2: '%AppData%\local'
|
||||
|
||||
- type: multistring
|
||||
reg_type: REG_MULTI_SZ
|
||||
data1: 'entry1' # test single entry as multi string
|
||||
data2: ['entry1', 2]
|
||||
value_null: []
|
||||
value1: ['entry1']
|
||||
value2: ['entry1', '2']
|
||||
|
||||
- type: binary
|
||||
reg_type: REG_BINARY
|
||||
data1: hex:00,01,ee,ff # testing hex string format with hex: in front
|
||||
data2: [0xff, 0xee, 0x01, 0x00] # testing using just raw hex values
|
||||
value_null: []
|
||||
value1: ["0x00", "0x01", "0xee", "0xff"]
|
||||
value2: ["0xff", "0xee", "0x01", "0x00"]
|
||||
|
||||
- type: none
|
||||
reg_type: REG_NONE
|
||||
data1: aa,bb,be,ef # testing hex string format with hex: in front
|
||||
data2: [0x01, 0x02]
|
||||
value_null: []
|
||||
value1: ["0xaa", "0xbb", "0xbe", "0xef"]
|
||||
value2: ["0x01", "0x02"]
|
||||
|
||||
- name: run remaining tests
|
||||
include_tasks: tests.yml
|
||||
|
||||
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}}'
|
||||
|
@ -0,0 +1,473 @@
|
||||
# test code for the win_regedit module
|
||||
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# clear the area of the registry we are using for tests
|
||||
|
||||
# test mangled registry key gets caught following https://github.com/ansible/ansible-modules-extras/issues/2412
|
||||
|
||||
- name: test mangled registry key is caught (avoids bizare error message from powershell)
|
||||
win_regedit:
|
||||
key: HKCU\Software
|
||||
value: invalid_key
|
||||
data: invalid_key
|
||||
datatype: string
|
||||
register: check00_result
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check00_result.failed == true"
|
||||
- "check00_result.msg == 'path: HKCU\\Software is not a valid powershell path, see module documentation for examples.'"
|
||||
|
||||
- name: remove setting
|
||||
win_regedit:
|
||||
key: 'HKCU:\SOFTWARE\Cow Corp'
|
||||
state: absent
|
||||
|
||||
- name: check basic set works
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hello
|
||||
data: world
|
||||
register: check01_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check01_result.changed == true"
|
||||
|
||||
- name: check that setting the same again is not changed
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hello
|
||||
data: world
|
||||
register: check02_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check02_result.changed == false"
|
||||
|
||||
# binary mode checks
|
||||
# tests with 'hex:' prefix (as intended)
|
||||
|
||||
- name: check binary with hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be,ef,be,ef,be,ef,be,ef,be,ef
|
||||
datatype: binary
|
||||
register: check03_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check03_result.changed == true"
|
||||
|
||||
- name: check binary with hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be,ef,be,ef,be,ef,be,ef,be,ef
|
||||
datatype: binary
|
||||
register: check04_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check04_result.changed == false"
|
||||
|
||||
- name: check binary with hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:de,ad,be,ef,de,ad,be,ef,de,ad,be,ef
|
||||
datatype: binary
|
||||
register: check05_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check05_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check06_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check06_result.changed == true"
|
||||
|
||||
# check without hex(colon) prefix
|
||||
|
||||
# tests without 'hex:' prefix (optional)
|
||||
- name: check binary with hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be,ef,be,ef,be,ef,be,ef,be,ef
|
||||
datatype: binary
|
||||
register: check13_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check13_result.changed == true"
|
||||
|
||||
- name: check binary without hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be,ef,be,ef,be,ef,be,ef,be,ef
|
||||
datatype: binary
|
||||
register: check14_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check14_result.changed == false"
|
||||
|
||||
- name: check binary without hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: de,ad,be,ef,de,ad,be,ef,de,ad,be,ef
|
||||
datatype: binary
|
||||
register: check15_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check15_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check16_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check16_result.changed == true"
|
||||
|
||||
# check mixed case hex values with hex: prefix
|
||||
|
||||
- name: check mixed case binary with hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be,EF,be,EF,be,EF,be,EF,be,EF
|
||||
datatype: binary
|
||||
register: check23_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check23_result.changed == true"
|
||||
|
||||
- name: check mixed case binary with hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be,EF,be,EF,be,EF,be,EF,be,EF
|
||||
datatype: binary
|
||||
register: check24_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check24_result.changed == false"
|
||||
|
||||
- name: check mixed case binary with hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:DE,ad,be,EF,DE,ad,be,EF,DE,ad,be,EF
|
||||
datatype: binary
|
||||
register: check25_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check25_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check26_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check26_result.changed == true"
|
||||
|
||||
# check mixed case without hex: prefix
|
||||
|
||||
# tests without 'hex:' prefix (optional)
|
||||
- name: check mixed case binary without hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be,EF,be,EF,be,EF,be,EF,be,EF
|
||||
datatype: binary
|
||||
register: check33_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check33_result.changed == true"
|
||||
|
||||
- name: check mixed case binary without hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be,EF,be,EF,be,EF,be,EF,be,EF
|
||||
datatype: binary
|
||||
register: check34_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check34_result.changed == false"
|
||||
|
||||
- name: check mixed case binary without hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: DE,ad,be,EF,DE,ad,be,EF,DE,ad,be,EF
|
||||
datatype: binary
|
||||
register: check35_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check35_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check36_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check36_result.changed == true"
|
||||
|
||||
# check colon separated hex values with hex: prefix
|
||||
|
||||
- name: check colon separated hex values with hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be:ef:be:ef:be:ef:be:ef:be:ef
|
||||
datatype: binary
|
||||
register: check43_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check43_result.changed == true"
|
||||
|
||||
- name: check colon separated binary with hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:be:ef:be:ef:be:ef:be:ef:be:ef
|
||||
datatype: binary
|
||||
register: check44_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check44_result.changed == false"
|
||||
|
||||
- name: check colon separated binary with hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: hex:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef
|
||||
datatype: binary
|
||||
register: check45_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check45_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check46_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check46_result.changed == true"
|
||||
|
||||
# check colon separated hex values without hex(colon) prefix
|
||||
|
||||
# tests without 'hex:' prefix (optional)
|
||||
- name: check colon separated binary with hex(colon) prefix
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be:ef:be:ef:be:ef:be:ef:be:ef
|
||||
datatype: binary
|
||||
register: check53_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check53_result.changed == true"
|
||||
|
||||
- name: check colon separated binary without hex(colon) prefix not modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: be:ef:be:ef:be:ef:be:ef:be:ef
|
||||
datatype: binary
|
||||
register: check54_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check54_result.changed == false"
|
||||
|
||||
- name: check colon separated binary without hex(colon) prefix modified
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
data: de:ad:be:ef:de:ad:be:ef:de:ad:be:ef
|
||||
datatype: binary
|
||||
register: check55_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check55_result.changed == true"
|
||||
|
||||
# reset
|
||||
- name: reset test
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hellobinary
|
||||
state: absent
|
||||
register: check56_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check56_result.changed == true"
|
||||
|
||||
# test empty data value (some things depend on this, having no data is not equivalent)
|
||||
|
||||
- name: set an empty data value
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: helloempty
|
||||
data: ""
|
||||
register: check61_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check61_result.changed == true"
|
||||
|
||||
- name: set an empty data value again (should not change)
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: helloempty
|
||||
data: ""
|
||||
register: check62_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check62_result.changed == false"
|
||||
|
||||
# check can use yaml array of bytes as input
|
||||
- name: regedit binary data using yaml syntax
|
||||
win_regedit:
|
||||
key: 'HKCU:\SOFTWARE\Cow Corp'
|
||||
value: hellobinaryfromyaml
|
||||
data: [0x21, 0xb3, 0x33, 0xf9, 0x0d, 0xff, 0xd0, 0x01]
|
||||
datatype: binary
|
||||
register: check63_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check63_result.changed == true"
|
||||
|
||||
- name: regedit binary data using yaml syntax again
|
||||
win_regedit:
|
||||
key: 'HKCU:\SOFTWARE\Cow Corp'
|
||||
value: hellobinaryfromyaml
|
||||
data: [0x21, 0xb3, 0x33, 0xf9, 0x0d, 0xff, 0xd0, 0x01]
|
||||
datatype: binary
|
||||
register: check64_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check64_result.changed == false"
|
||||
|
||||
# test dword
|
||||
|
||||
- name: check basic set dword works
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hello_dword
|
||||
data: 00000000
|
||||
datatype: dword
|
||||
register: check71_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check71_result.changed == true"
|
||||
|
||||
- name: check that setting the same dword again is not changed
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: hello_dword
|
||||
data: 00000000
|
||||
datatype: dword
|
||||
register: check72_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "check72_result.changed == false"
|
||||
|
||||
# https://github.com/ansible/ansible/issues/26049
|
||||
# module reports change on dword with hex value even with same value
|
||||
- name: create hex value with prepending 0x
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: full_hex_dword
|
||||
data: 0xffffffff
|
||||
datatype: dword
|
||||
register: dword_create
|
||||
|
||||
- name: change hex value and report no changes
|
||||
win_regedit:
|
||||
key: HKCU:\Software\Cow Corp
|
||||
value: full_hex_dword
|
||||
data: 0xffffffff
|
||||
datatype: dword
|
||||
register: dword_create_again
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not dword_create_again|changed
|
||||
|
||||
# tear down
|
||||
|
||||
- name: remove registry key used for testing
|
||||
win_regedit:
|
||||
key: 'HKCU:\SOFTWARE\Cow Corp'
|
||||
state: absent
|
||||
|
||||
|
||||
# END OF win_regedit tests
|
@ -0,0 +1,423 @@
|
||||
---
|
||||
- name: fail run win_regedit with larger dword
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: test
|
||||
data: 0xffffffff1
|
||||
type: dword
|
||||
state: present
|
||||
register: large_dword
|
||||
failed_when: large_dword.msg != 'data cannot be larger than 0xffffffff when type is dword'
|
||||
|
||||
- name: fail run win_regedit with larger qword
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: test
|
||||
data: 0xffffffffffffffff1
|
||||
type: qword
|
||||
state: present
|
||||
register: large_qword
|
||||
failed_when: large_qword.msg != 'data cannot be larger than 0xffffffffffffffff when type is qword'
|
||||
|
||||
- name: run win_regedit with invalid path
|
||||
win_regedit:
|
||||
path: ABCD:\efg
|
||||
register: invalid_path
|
||||
failed_when: "invalid_path.msg != 'path: ABCD:\\efg is not a valid powershell path, see module documentation for examples.'"
|
||||
|
||||
- name: change string to binary check
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_string
|
||||
data: hex:00,01
|
||||
type: binary
|
||||
state: present
|
||||
register: change_string_binary_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual change string to binary check
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_string
|
||||
register: change_string_binary_actual_check
|
||||
|
||||
- name: assert change string to binary check
|
||||
assert:
|
||||
that:
|
||||
- change_string_binary_check|changed
|
||||
- change_string_binary_check.data_changed == True
|
||||
- change_string_binary_check.data_type_changed == True
|
||||
- change_string_binary_actual_check.type == 'REG_SZ'
|
||||
- change_string_binary_actual_check.raw_value == "new hello world"
|
||||
|
||||
- name: change string to binary
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_string
|
||||
data: hex:00,01
|
||||
type: binary
|
||||
state: present
|
||||
register: change_string_binary
|
||||
|
||||
- name: get actual change string to binary
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_string
|
||||
register: change_string_binary_actual
|
||||
|
||||
- name: assert change string to binary check
|
||||
assert:
|
||||
that:
|
||||
- change_string_binary|changed
|
||||
- change_string_binary.data_changed == True
|
||||
- change_string_binary.data_type_changed == True
|
||||
- change_string_binary_actual.type == 'REG_BINARY'
|
||||
- change_string_binary_actual.raw_value == ["0x00", "0x01"]
|
||||
|
||||
- name: modify the (Default) key property check
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
data: default value
|
||||
state: present
|
||||
register: modify_default_check
|
||||
check_mode: yes
|
||||
|
||||
# win_reg_stat struggles with the (Default) property just use powershell
|
||||
- name: get actual modify the (Default) key property check
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue($null, $null)"
|
||||
register: modify_default_actual_check
|
||||
|
||||
- name: assert modify the (Default) key property check
|
||||
assert:
|
||||
that:
|
||||
- modify_default_check|changed
|
||||
- modify_default_actual_check.stdout == ""
|
||||
|
||||
- name: modify the (Default) key property
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
data: default value
|
||||
state: present
|
||||
register: modify_default
|
||||
|
||||
- name: get actual modify the (Default) key property
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue($null, $null)"
|
||||
register: modify_default_actual
|
||||
|
||||
- name: assert modify the (Default) key property
|
||||
assert:
|
||||
that:
|
||||
- modify_default|changed
|
||||
- modify_default_actual.stdout == "default value\r\n"
|
||||
|
||||
- name: create an actual property called (Default)
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: (Default)
|
||||
data: custom default value
|
||||
type: expandstring
|
||||
state: present
|
||||
register: create_specific_default_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual value for (Default) property to ensure it didn't change check
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue($null, $null)"
|
||||
register: create_specific_default_actual_default_check
|
||||
|
||||
- name: get actual for create specific property called (Default) check
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue('(Default)', $null)"
|
||||
register: create_specific_default_actual_check
|
||||
|
||||
- name: assert create specific property called (Default) check
|
||||
assert:
|
||||
that:
|
||||
- create_specific_default_check|changed
|
||||
- create_specific_default_actual_default_check.stdout == "default value\r\n"
|
||||
- create_specific_default_actual_check.stdout == ""
|
||||
|
||||
- name: create an actual property called (Default)
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: (Default)
|
||||
data: custom default value
|
||||
type: expandstring
|
||||
state: present
|
||||
register: create_specific_default
|
||||
|
||||
- name: get actual value for (Default) property to ensure it didn't change
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue($null, $null)"
|
||||
register: create_specific_default_actual_default
|
||||
|
||||
- name: get actual for specific property called (Default)
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue('(Default)', $null)"
|
||||
register: create_specific_default_actual
|
||||
|
||||
- name: assert create specific property called (Default)
|
||||
assert:
|
||||
that:
|
||||
- create_specific_default|changed
|
||||
- create_specific_default_actual_default.stdout == "default value\r\n"
|
||||
- create_specific_default_actual.stdout == "custom default value\r\n"
|
||||
|
||||
- name: delete property check
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_binary
|
||||
state: absent
|
||||
register: delete_property_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual of delete property check
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_binary
|
||||
register: delete_property_actual_check
|
||||
|
||||
- name: assert delete property check
|
||||
assert:
|
||||
that:
|
||||
- delete_property_check|changed
|
||||
- delete_property_actual_check.exists == True
|
||||
|
||||
- name: delete property
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_binary
|
||||
state: absent
|
||||
register: delete_property
|
||||
|
||||
- name: get actual of delete property
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_binary
|
||||
register: delete_property_actual
|
||||
|
||||
- name: assert delete property
|
||||
assert:
|
||||
that:
|
||||
- delete_property|changed
|
||||
- delete_property_actual.exists == False
|
||||
|
||||
- name: delete property again
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: data_binary
|
||||
state: absent
|
||||
register: delete_property_again
|
||||
|
||||
- name: assert delete property again
|
||||
assert:
|
||||
that:
|
||||
- not delete_property_again|changed
|
||||
|
||||
- name: delete the key's (Default) property check
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
state: absent
|
||||
delete_key: no
|
||||
register: delete_default_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual of key's (Default) property check
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue($null, $null)"
|
||||
register: delete_default_actual_check
|
||||
|
||||
- name: get actual of custom (Default) property check
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue('(Default)', $null)"
|
||||
register: delete_default_custom_actual_check
|
||||
|
||||
- name: assert delete the key's (Default) property check
|
||||
assert:
|
||||
that:
|
||||
- delete_default_check|changed
|
||||
- delete_default_actual_check.stdout == "default value\r\n"
|
||||
- delete_default_custom_actual_check.stdout == "custom default value\r\n"
|
||||
|
||||
- name: delete the key's (Default) property
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
state: absent
|
||||
delete_key: no
|
||||
register: delete_default
|
||||
|
||||
- name: get actual of key's (Default) property
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue($null, $null)"
|
||||
register: delete_default_actual
|
||||
|
||||
- name: get actual of custom (Default) property
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue('(Default)', $null)"
|
||||
register: delete_default_custom_actual
|
||||
|
||||
- name: assert delete the key's (Default) property
|
||||
assert:
|
||||
that:
|
||||
- delete_default|changed
|
||||
- delete_default_actual.stdout == ""
|
||||
- delete_default_custom_actual.stdout == "custom default value\r\n"
|
||||
|
||||
- name: recreate the key's (Default) property for next test
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
data: default value
|
||||
|
||||
- name: delete the custom (Default) property check
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: (Default)
|
||||
state: absent
|
||||
delete_key: no
|
||||
register: delete_custom_default_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual of key's (Default) property check
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue($null, $null)"
|
||||
register: delete_custom_default_actual_check
|
||||
|
||||
- name: get actual of custom (Default) property check
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue('(Default)', $null)"
|
||||
register: delete_custom_default_custom_actual_check
|
||||
|
||||
- name: assert delete the custom (Default) property check
|
||||
assert:
|
||||
that:
|
||||
- delete_custom_default_check|changed
|
||||
- delete_custom_default_actual_check.stdout == "default value\r\n"
|
||||
- delete_custom_default_custom_actual_check.stdout == "custom default value\r\n"
|
||||
|
||||
- name: delete the custom (Default) property
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
name: (Default)
|
||||
state: absent
|
||||
delete_key: no
|
||||
register: delete_custom_default
|
||||
|
||||
- name: get actual of key's (Default) property
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue($null, $null)"
|
||||
register: delete_custom_default_actual
|
||||
|
||||
- name: get actual of custom (Default) property
|
||||
win_command: powershell.exe "(Get-Item -Path '{{test_win_regedit_local_key}}').GetValue('(Default)', $null)"
|
||||
register: delete_custom_default_custom_actual
|
||||
|
||||
- name: assert delete the custom (Default) property
|
||||
assert:
|
||||
that:
|
||||
- delete_custom_default|changed
|
||||
- delete_custom_default_actual.stdout == "default value\r\n"
|
||||
- delete_custom_default_custom_actual.stdout == ""
|
||||
|
||||
- name: add some nested keys for later deletion
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}\{{item}}'
|
||||
state: present
|
||||
items:
|
||||
- nest1
|
||||
- nest2
|
||||
- nest1\nested
|
||||
|
||||
- name: delete key and it's sub keys check
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
state: absent
|
||||
delete_key: yes
|
||||
register: delete_key_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual of delete key and it's sub keys check
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
register: delete_key_actual_check
|
||||
|
||||
- name: assert delete key and it's sub keys check
|
||||
assert:
|
||||
that:
|
||||
- delete_key_check|changed
|
||||
- delete_key_actual_check.exists
|
||||
- delete_key_actual_check.sub_keys == ["nest1", "nest2"]
|
||||
|
||||
- name: delete key and it's sub keys
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
state: absent
|
||||
delete_key: yes
|
||||
register: delete_key
|
||||
|
||||
- name: get actual of delete key and it's sub keys
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
register: delete_key_actual
|
||||
|
||||
- name: assert delete key and it's sub keys
|
||||
assert:
|
||||
that:
|
||||
- delete_key|changed
|
||||
- delete_key_actual.exists == False
|
||||
|
||||
- name: delete key and it's sub keys again
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_local_key}}'
|
||||
state: absent
|
||||
delete_key: yes
|
||||
register: delete_key_again
|
||||
|
||||
- name: assert delete key and it's sub keys again
|
||||
assert:
|
||||
that:
|
||||
- not delete_key_again|changed
|
||||
|
||||
- name: create key in HKEY_CLASSES_ROOT check
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_classes_key}}'
|
||||
name: test
|
||||
data: test
|
||||
type: string
|
||||
state: present
|
||||
register: create_hkcr_key_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual of create key in HKEY_CLASSES_ROOT check
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_classes_key}}'
|
||||
register: create_hkcr_key_actual_check
|
||||
|
||||
- name: assert create key in HKEY_CLASSES_ROOT check
|
||||
assert:
|
||||
that:
|
||||
- create_hkcr_key_check|changed
|
||||
- create_hkcr_key_actual_check.exists == False
|
||||
|
||||
- name: create key in HKEY_CLASSES_ROOT
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_classes_key}}'
|
||||
name: test
|
||||
data: test
|
||||
type: string
|
||||
state: present
|
||||
register: create_hkcr_key
|
||||
|
||||
- name: get actual of create key in HKEY_CLASSES_ROOT
|
||||
win_reg_stat:
|
||||
path: '{{test_win_regedit_classes_key}}'
|
||||
register: create_hkcr_key_actual
|
||||
|
||||
- name: assert create key in HKEY_CLASSES_ROOT
|
||||
assert:
|
||||
that:
|
||||
- create_hkcr_key|changed
|
||||
- create_hkcr_key_actual.exists == True
|
||||
- create_hkcr_key_actual.properties.test is defined
|
||||
|
||||
- name: create key in HKEY_CLASSES_ROOT again
|
||||
win_regedit:
|
||||
path: '{{test_win_regedit_classes_key}}'
|
||||
name: test
|
||||
data: test
|
||||
type: string
|
||||
state: present
|
||||
register: create_hkcr_key_again
|
||||
|
||||
- name: assert create key in HKEY_CLASSES_ROOT again
|
||||
assert:
|
||||
that:
|
||||
- not create_hkcr_key_again|changed
|
Loading…
Reference in New Issue