Debian Codegraph @

ansible_collections/community/windows/tests/integration/targets/win_snmp/tasks/snmp_community.yml

raw
1 ---
2 - name: Add initial SNMP community
3 register: snmp_community
4 win_snmp:
5 action: add
6 community_strings:
7 - ansible-ro-test
8
9 - name: Check initial SNMP community exists in registry
10 register: snmp_community_reg
11 ansible.windows.win_reg_stat:
12 path: "{{ valid_communities_key }}"
13 name: ansible-ro-test
14
15 - name: Assert initial SNMP community is correct
16 assert:
17 that:
18 - snmp_community is changed
19 - snmp_community_reg.exists
20 - snmp_community_reg.type == 'REG_DWORD'
21 - snmp_community_reg.value == 4
22
23 - name: Add initial SNMP community again
24 register: snmp_community_again
25 win_snmp:
26 action: add
27 community_strings:
28 - ansible-ro-test
29
30 - name: Check no change occurred when adding SNMP community again
31 assert:
32 that:
33 - snmp_community_again is not changed
34
35 - name: Add next SNMP community
36 register: snmp_community_next
37 win_snmp:
38 action: add
39 community_strings:
40 - ansible-ro-test-next
41
42 - name: Check initial SNMP community still exists in registry
43 register: snmp_community_reg_orig
44 ansible.windows.win_reg_stat:
45 path: "{{ valid_communities_key }}"
46 name: ansible-ro-test
47
48 - name: Check next SNMP community exists in registry
49 register: snmp_community_reg_next
50 ansible.windows.win_reg_stat:
51 path: "{{ valid_communities_key }}"
52 name: ansible-ro-test-next
53
54 - name: Assert initial SNMP community still exists
55 assert:
56 that:
57 - snmp_community_reg_orig.exists
58 - snmp_community_reg_orig.type == 'REG_DWORD'
59 - snmp_community_reg_orig.value == 4
60
61 - name: Assert next SNMP community exists
62 assert:
63 that:
64 - snmp_community_next is changed
65 - snmp_community_reg_next.exists
66 - snmp_community_reg_next.type == 'REG_DWORD'
67 - snmp_community_reg_next.value == 4
68
69 - name: Replace SNMP community
70 register: snmp_community_replace
71 win_snmp:
72 action: set
73 community_strings:
74 - ansible-ro-test-replace
75
76 - name: Check initial SNMP community does not exist in registry
77 register: snmp_community_reg_orig_replace
78 ansible.windows.win_reg_stat:
79 path: "{{ valid_communities_key }}"
80 name: ansible-ro-test
81
82 - name: Check next SNMP community does not exist in registry
83 register: snmp_community_reg_next_replace
84 ansible.windows.win_reg_stat:
85 path: "{{ valid_communities_key }}"
86 name: ansible-ro-test-next
87
88 - name: Check replace SNMP community exists in registry
89 register: snmp_community_reg_replace
90 ansible.windows.win_reg_stat:
91 path: "{{ valid_communities_key }}"
92 name: ansible-ro-test-replace
93
94 - name: Assert replace SNMP community exists and others are replaced
95 assert:
96 that:
97 - snmp_community_replace is changed
98 - snmp_community_reg_orig_replace.exists == false
99 - snmp_community_reg_next_replace.exists == false
100 - snmp_community_reg_replace.exists
101 - snmp_community_reg_replace.type == 'REG_DWORD'
102 - snmp_community_reg_replace.value == 4
103
104 # This task has already been tested
105 - name: Add another SNMP community before testing removal
106 win_snmp:
107 action: add
108 community_strings:
109 - ansible-ro-remove-add
110
111 - name: Remove the replaced SNMP community
112 register: snmp_community_remove
113 win_snmp:
114 action: remove
115 community_strings:
116 - ansible-ro-test-replace
117
118 - name: Check replace SNMP community is removed in registry
119 register: snmp_community_reg_remove
120 ansible.windows.win_reg_stat:
121 path: "{{ valid_communities_key }}"
122 name: ansible-ro-test-replace
123
124 - name: Check SNMP community that was added for testing removal exists in registry
125 register: snmp_community_reg_remove_add
126 ansible.windows.win_reg_stat:
127 path: "{{ valid_communities_key }}"
128 name: ansible-ro-remove-add
129
130 - name: Assert removal of SNMP community succeeded and next SNMP community remains
131 assert:
132 that:
133 - snmp_community_remove is changed
134 - snmp_community_reg_remove.exists == false
135 - snmp_community_reg_remove_add.exists
136 - snmp_community_reg_remove_add.type == 'REG_DWORD'
137 - snmp_community_reg_remove_add.value == 4
138
139 - name: Remove the replaced SNMP community (again)
140 register: snmp_community_remove
141 win_snmp:
142 action: remove
143 community_strings:
144 - ansible-ro-test-replace
145
146 - name: Check replace SNMP community is removed in registry (again)
147 register: snmp_community_reg_remove
148 ansible.windows.win_reg_stat:
149 path: "{{ valid_communities_key }}"
150 name: ansible-ro-test-replace
151
152 - name: Check SNMP community that was added for testing removal exists in registry (again)
153 register: snmp_community_reg_remove_add
154 ansible.windows.win_reg_stat:
155 path: "{{ valid_communities_key }}"
156 name: ansible-ro-remove-add
157
158 - name: Assert removal of SNMP community succeeded and next SNMP community remains (again)
159 assert:
160 that:
161 - snmp_community_remove is not changed
162 - snmp_community_reg_remove.exists == false
163 - snmp_community_reg_remove_add.exists
164 - snmp_community_reg_remove_add.type == 'REG_DWORD'
165 - snmp_community_reg_remove_add.value == 4