Debian Codegraph @

ansible_collections/cisco/intersight/tests/integration/targets/intersight_ssh_policy/tasks/tests.yml

raw
1 ---
2 - block:
3 - name: Define anchor for Intersight API login info
4 ansible.builtin.set_fact:
5 api_info: &api_info
6 api_private_key: "{{ api_private_key }}"
7 api_key_id: "{{ api_key_id }}"
8 api_uri: "{{ api_uri | default(omit) }}"
9 validate_certs: "{{ validate_certs | default(omit) }}"
10 organization: "{{ organization }}"
11
12 - name: Make sure Env is clean
13 cisco.intersight.intersight_ssh_policy:
14 <<: *api_info
15 name: "{{ item }}"
16 state: absent
17 loop:
18 - test_ssh_policy
19 - test_ssh_policy_custom
20 - test_ssh_policy_disabled
21
22 - name: Create SSH policy - check-mode
23 cisco.intersight.intersight_ssh_policy:
24 <<: *api_info
25 name: test_ssh_policy
26 description: "Test SSH policy description"
27 tags:
28 - Key: Site
29 Value: Test
30 - Key: Environment
31 Value: CI
32 enable_ssh: true
33 ssh_port: 22
34 ssh_timeout: 1800
35 check_mode: true
36 register: creation_res_check_mode
37
38 - name: Verify SSH policy was not created - check-mode
39 ansible.builtin.assert:
40 that:
41 - creation_res_check_mode is changed
42 - creation_res_check_mode.api_response == {}
43
44 - name: Create SSH policy with default settings
45 cisco.intersight.intersight_ssh_policy:
46 <<: *api_info
47 name: test_ssh_policy
48 description: "Test SSH policy description"
49 tags:
50 - Key: Site
51 Value: Test
52 - Key: Environment
53 Value: CI
54 enable_ssh: true
55 ssh_port: 22
56 ssh_timeout: 1800
57 register: creation_res
58
59 - name: Fetch info after creation
60 cisco.intersight.intersight_ssh_policy_info:
61 <<: *api_info
62 name: test_ssh_policy
63 register: creation_info_res
64
65 - name: Verify SSH policy creation by info
66 ansible.builtin.assert:
67 that:
68 - creation_res.changed
69 - creation_info_res.api_response[0].Name == 'test_ssh_policy'
70 - creation_info_res.api_response[0].Enabled == true
71 - creation_info_res.api_response[0].Port == 22
72 - creation_info_res.api_response[0].Timeout == 1800
73
74 - name: Verify SSH policy creation response aligns with info response
75 ansible.builtin.assert:
76 that:
77 - creation_res.api_response.Name == creation_info_res.api_response[0].Name
78 - creation_res.api_response.Enabled == creation_info_res.api_response[0].Enabled
79 - creation_res.api_response.Port == creation_info_res.api_response[0].Port
80 - creation_res.api_response.Timeout == creation_info_res.api_response[0].Timeout
81
82 - name: Create SSH policy (idempotency check)
83 cisco.intersight.intersight_ssh_policy:
84 <<: *api_info
85 name: test_ssh_policy
86 description: "Test SSH policy description"
87 tags:
88 - Key: Site
89 Value: Test
90 - Key: Environment
91 Value: CI
92 enable_ssh: true
93 ssh_port: 22
94 ssh_timeout: 1800
95 register: creation_res_ide
96
97 - name: Verify SSH policy creation (idempotency check)
98 ansible.builtin.assert:
99 that:
100 - not creation_res_ide.changed
101
102 - name: Change settings on existing SSH policy
103 cisco.intersight.intersight_ssh_policy:
104 <<: *api_info
105 name: test_ssh_policy
106 description: "Updated SSH policy description"
107 enable_ssh: true
108 ssh_port: 2222
109 ssh_timeout: 3600
110 register: changed_res
111
112 - name: Fetch info after change
113 cisco.intersight.intersight_ssh_policy_info:
114 <<: *api_info
115 name: test_ssh_policy
116 register: change_info_res
117
118 - name: Verify SSH policy change by info
119 ansible.builtin.assert:
120 that:
121 - changed_res.changed
122 - change_info_res.api_response[0].Name == 'test_ssh_policy'
123 - change_info_res.api_response[0].Description == 'Updated SSH policy description'
124 - change_info_res.api_response[0].Port == 2222
125 - change_info_res.api_response[0].Timeout == 3600
126
127 - name: Create SSH policy with custom port and timeout
128 cisco.intersight.intersight_ssh_policy:
129 <<: *api_info
130 name: test_ssh_policy_custom
131 description: "SSH policy with custom settings"
132 enable_ssh: true
133 ssh_port: 8022
134 ssh_timeout: 7200
135 register: creation_res_custom
136
137 - name: Verify custom SSH policy creation
138 cisco.intersight.intersight_ssh_policy_info:
139 <<: *api_info
140 name: test_ssh_policy_custom
141 register: creation_info_res_custom
142
143 - name: Verify custom SSH policy has correct settings
144 ansible.builtin.assert:
145 that:
146 - creation_info_res_custom.api_response[0].Enabled == true
147 - creation_info_res_custom.api_response[0].Port == 8022
148 - creation_info_res_custom.api_response[0].Timeout == 7200
149
150 - name: Create SSH policy with SSH disabled
151 cisco.intersight.intersight_ssh_policy:
152 <<: *api_info
153 name: test_ssh_policy_disabled
154 description: "SSH policy with SSH disabled"
155 enable_ssh: false
156 register: creation_res_disabled
157
158 - name: Verify disabled SSH policy creation
159 cisco.intersight.intersight_ssh_policy_info:
160 <<: *api_info
161 name: test_ssh_policy_disabled
162 register: creation_info_res_disabled
163
164 - name: Verify disabled SSH policy has correct settings
165 ansible.builtin.assert:
166 that:
167 - creation_info_res_disabled.api_response[0].Enabled == false
168 - creation_info_res_disabled.api_response[0].Name == 'test_ssh_policy_disabled'
169
170 - name: Test enabling SSH on disabled policy
171 cisco.intersight.intersight_ssh_policy:
172 <<: *api_info
173 name: test_ssh_policy_disabled
174 description: "SSH policy now enabled"
175 enable_ssh: true
176 ssh_port: 22
177 ssh_timeout: 1800
178 register: enable_ssh_res
179
180 - name: Verify SSH was enabled correctly
181 cisco.intersight.intersight_ssh_policy_info:
182 <<: *api_info
183 name: test_ssh_policy_disabled
184 register: enable_ssh_info
185
186 - name: Assert SSH was enabled with correct parameters
187 ansible.builtin.assert:
188 that:
189 - enable_ssh_res.changed
190 - enable_ssh_info.api_response[0].Enabled == true
191 - enable_ssh_info.api_response[0].Port == 22
192 - enable_ssh_info.api_response[0].Timeout == 1800
193
194 - name: Fetch all SSH policies under selected organization
195 cisco.intersight.intersight_ssh_policy_info:
196 <<: *api_info
197 register: creation_info_res_final
198
199 - name: Check that there are at least three SSH policies under this organization
200 ansible.builtin.assert:
201 that:
202 - creation_info_res_final.api_response | length >= 3
203
204 always:
205 - name: Remove SSH policies
206 cisco.intersight.intersight_ssh_policy:
207 <<: *api_info
208 name: "{{ item }}"
209 state: absent
210 loop:
211 - test_ssh_policy
212 - test_ssh_policy_custom
213 - test_ssh_policy_disabled