summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/win_regmerge/tasks/main.yml
blob: 6e64c9dd4a70ca9fb4823c432235c64ff0a7e864 (plain)
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
# test code for the win_regmerge 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
- name: remove setting
  win_regedit:
    key: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp'
    state: absent

# copy over some registry files to work with
- name: copy over some registry files to work with
  win_copy: src={{item}} dest={{win_output_dir}}\\{{item}}
  with_items:
     - settings1.reg
     - settings2.reg
     - settings3.reg

# test 1 -  basic test of changed behaviour
# merge in REG_SZ 
- name: test 1 merge in a setting
  win_regmerge:
     path: "{{win_output_dir}}\\settings1.reg"
  register: merge11_result

- assert:
    that:
      - "merge11_result.changed == true"

# re run the merge
- name: test 1 merge in the setting again
  win_regmerge:
     path: "{{win_output_dir}}\\settings1.reg"
  register: merge12_result

# without a compare to key, should allways report changed
- assert:
    that:
      - "merge12_result.changed == true"
# assert changed false

# prune reg key
- name: test 1 remove setting
  win_regedit:
     key: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp'
     state: absent

#
# test 2, observe behaviour when compare_to param is set
#
- name: test 2 merge in a setting
  win_regmerge:
    path: "{{win_output_dir}}\\settings1.reg"
    compare_to: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp\Moosic\ILikeToMooveIt'
  register: merge21_result

- assert:
    that:
      - "merge21_result.changed == true"

# re run the merge
- name: test 2 merge in the setting again but with compare_key
  win_regmerge:
    path: "{{win_output_dir}}\\settings1.reg"
    compare_to: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp\Moosic\ILikeToMooveIt'
  register: merge22_result

# with a compare to key, should now report not changed
- assert:
    that:
      - "merge22_result.changed == false"
# assert changed false

# prune the contents of the registry from the parent of the compare key downwards
- name: test 2 clean up remove setting
  win_regedit:
    key: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp'
    state: absent

# test 3 merge in more complex settings
- name: test 3 merge in a setting
  win_regmerge:
    path: "{{win_output_dir}}\\settings3.reg"
    compare_to: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp\Moo Monitor'
  register: merge31_result

- assert:
    that:
      - "merge31_result.changed == true"

# re run the merge
- name: test 3 merge in the setting again but with compare_key check
  win_regmerge:
    path: "{{win_output_dir}}\\settings3.reg"
    compare_to: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp\Moo Monitor'
  register: merge32_result

# with a compare to key, should now report not changed
- assert:
    that:
      - "merge32_result.changed == false"
# assert changed false

# prune the contents of the registry from the compare key downwards
- name: test 3 clean up remove setting
  win_regedit:
    key: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp'
    state: absent

# clean up registry files

- name: clean up registry files
  win_file: path={{win_output_dir}}\\{{item}} state=absent
  with_items:
     - settings1.reg
     - settings2.reg
     - settings3.reg

# END OF win_regmerge tests