Debian Codegraph @

ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/tasks/test.yml

raw
1 # Copyright: (c) 2019, Hetzner Cloud GmbH <[email protected]>
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3 ---
4 - name: setup ensure server is absent
5 hetzner.hcloud.server:
6 name: "{{ hcloud_server_name }}"
7 state: absent
8
9 - name: setup ensure another server is absent
10 hetzner.hcloud.server:
11 name: "{{ hcloud_server_name }}2"
12 state: absent
13
14 - name: setup ensure floating ip is absent
15 hetzner.hcloud.floating_ip:
16 name: "{{ hcloud_floating_ip_name }}"
17 state: absent
18
19 - name: setup server
20 hetzner.hcloud.server:
21 name: "{{ hcloud_server_name }}"
22 server_type: "{{ hcloud_server_type_name }}"
23 image: "{{ hcloud_image_name }}"
24 location: "{{ hcloud_location_name }}"
25 state: created
26 register: main_server
27 - name: verify setup server
28 assert:
29 that:
30 - main_server is changed
31
32 - name: setup another server
33 hetzner.hcloud.server:
34 name: "{{ hcloud_server_name }}2"
35 server_type: "{{ hcloud_server_type_name }}"
36 image: "{{ hcloud_image_name }}"
37 location: "{{ hcloud_location_name }}"
38 state: created
39 register: main_server2
40 - name: verify setup another server
41 assert:
42 that:
43 - main_server2 is changed
44
45 - name: test missing type parameter on create Floating IP
46 hetzner.hcloud.floating_ip:
47 name: "{{ hcloud_floating_ip_name }}"
48 register: result
49 ignore_errors: true
50 - name: verify fail test missing type parameter on create Floating IP
51 assert:
52 that:
53 - result is failed
54 - 'result.msg == "missing required arguments: type"'
55
56 - name: test missing required parameters on create Floating IP
57 hetzner.hcloud.floating_ip:
58 name: "{{ hcloud_floating_ip_name }}"
59 type: ipv4
60 register: result
61 ignore_errors: true
62 - name: verify fail test missing required parameters on create Floating IP
63 assert:
64 that:
65 - result is failed
66 - 'result.msg == "one of the following is required: home_location, server"'
67
68 - name: test missing type parameter on delete Floating IP
69 hetzner.hcloud.floating_ip:
70 type: ipv4
71 home_location: "{{ hcloud_location_name }}"
72 state: "absent"
73 register: result
74 ignore_errors: true
75 - name: verify fail test missing type parameter on delete Floating IP
76 assert:
77 that:
78 - result is failed
79 - 'result.msg == "one of the following is required: id, name"'
80
81 - name: test invalid type
82 hetzner.hcloud.floating_ip:
83 name: "{{ hcloud_floating_ip_name }}"
84 type: ipv5
85 home_location: "{{ hcloud_location_name }}"
86 register: result
87 ignore_errors: true
88 - name: verify invalid type
89 assert:
90 that:
91 - result is failed
92 - 'result.msg == "value of type must be one of: ipv4, ipv6, got: ipv5"'
93
94 - name: test invalid location
95 hetzner.hcloud.floating_ip:
96 name: "{{ hcloud_floating_ip_name }}"
97 type: ipv4
98 home_location: "abc"
99 register: result
100 ignore_errors: true
101 - name: verify invalid location
102 assert:
103 that:
104 - result is failed
105 - result.failure.code == "invalid_input"
106 - result.failure.message == "invalid input in fields 'server', 'home_location'"
107
108 - name: test create Floating IP with check mode
109 hetzner.hcloud.floating_ip:
110 name: "{{ hcloud_floating_ip_name }}"
111 description: "Web Server"
112 type: ipv4
113 home_location: "{{ hcloud_location_name }}"
114 register: floatingIP
115 check_mode: true
116 - name: verify test create Floating IP with check mode
117 assert:
118 that:
119 - floatingIP is changed
120
121 - name: test create Floating IP
122 hetzner.hcloud.floating_ip:
123 name: "{{ hcloud_floating_ip_name }}"
124 description: "Web Server"
125 type: ipv4
126 home_location: "{{ hcloud_location_name }}"
127 register: floatingIP
128 - name: verify test create Floating IP
129 assert:
130 that:
131 - floatingIP is changed
132 - floatingIP.hcloud_floating_ip.name ==hcloud_floating_ip_name
133 - floatingIP.hcloud_floating_ip.description == "Web Server"
134 - floatingIP.hcloud_floating_ip.home_location == hcloud_location_name
135
136 - name: test create Floating IP idempotency
137 hetzner.hcloud.floating_ip:
138 name: "{{ hcloud_floating_ip_name }}"
139 description: "Web Server"
140 type: ipv4
141 home_location: "{{ hcloud_location_name }}"
142 register: floatingIP
143 - name: verify test create Floating IP idempotency
144 assert:
145 that:
146 - floatingIP is not changed
147
148 - name: test update Floating IP with check mode
149 hetzner.hcloud.floating_ip:
150 name: "{{ hcloud_floating_ip_name }}"
151 description: "changed-description"
152 type: ipv4
153 home_location: "{{ hcloud_location_name }}"
154 check_mode: true
155 register: floatingIP
156 - name: verify test create Floating IP with check mode
157 assert:
158 that:
159 - floatingIP is changed
160 - floatingIP.hcloud_floating_ip.description == "Web Server"
161
162 - name: test update Floating IP
163 hetzner.hcloud.floating_ip:
164 name: "{{ hcloud_floating_ip_name }}"
165 description: "changed-description"
166 type: ipv4
167 home_location: "{{ hcloud_location_name }}"
168 labels:
169 key: value
170 register: floatingIP
171 - name: verify test update Floating IP
172 assert:
173 that:
174 - floatingIP is changed
175 - floatingIP.hcloud_floating_ip.description == "changed-description"
176
177 - name: test update Floating IP idempotency
178 hetzner.hcloud.floating_ip:
179 name: "{{ hcloud_floating_ip_name }}"
180 description: "changed-description"
181 type: ipv4
182 home_location: "{{ hcloud_location_name }}"
183 labels:
184 key: value
185 register: floatingIP
186 - name: verify test update Floating IP idempotency
187 assert:
188 that:
189 - floatingIP is not changed
190
191 - name: test update Floating IP with same labels
192 hetzner.hcloud.floating_ip:
193 name: "{{ hcloud_floating_ip_name }}"
194 type: ipv4
195 home_location: "{{ hcloud_location_name }}"
196 labels:
197 key: value
198 register: floatingIP
199 - name: verify test update Floating IP with same labels
200 assert:
201 that:
202 - floatingIP is not changed
203
204 - name: test update Floating IP with other labels
205 hetzner.hcloud.floating_ip:
206 name: "{{ hcloud_floating_ip_name }}"
207 type: ipv4
208 home_location: "{{ hcloud_location_name }}"
209 labels:
210 key: value
211 other: label
212 register: floatingIP
213 - name: verify test update Floating IP with other labels
214 assert:
215 that:
216 - floatingIP is changed
217
218 - name: test update Floating IP with other labels in different order
219 hetzner.hcloud.floating_ip:
220 name: "{{ hcloud_floating_ip_name }}"
221 type: ipv4
222 home_location: "{{ hcloud_location_name }}"
223 labels:
224 other: label
225 key: value
226 register: floatingIP
227 - name: verify test update Floating IP with other labels in different order
228 assert:
229 that:
230 - floatingIP is not changed
231
232 - name: test assign Floating IP with checkmode
233 hetzner.hcloud.floating_ip:
234 name: "{{ hcloud_floating_ip_name }}"
235 description: "changed-description"
236 type: ipv4
237 server: "{{ main_server.hcloud_server.name }}"
238 check_mode: true
239 register: floatingIP
240 - name: verify test assign Floating IP with checkmode
241 assert:
242 that:
243 - floatingIP is changed
244 - floatingIP.hcloud_floating_ip.server != main_server.hcloud_server.name
245
246 - name: test assign Floating IP
247 hetzner.hcloud.floating_ip:
248 name: "{{ hcloud_floating_ip_name }}"
249 description: "changed-description"
250 type: ipv4
251 server: "{{ main_server.hcloud_server.name }}"
252 register: floatingIP
253 - name: verify test assign Floating IP
254 assert:
255 that:
256 - floatingIP is changed
257 - floatingIP.hcloud_floating_ip.server == main_server.hcloud_server.name
258
259 - name: test assign Floating IP idempotency
260 hetzner.hcloud.floating_ip:
261 name: "{{ hcloud_floating_ip_name }}"
262 description: "changed-description"
263 type: ipv4
264 server: "{{ main_server.hcloud_server.name }}"
265 register: floatingIP
266 - name: verify test unassign Floating IPidempotency
267 assert:
268 that:
269 - floatingIP is not changed
270
271 - name: test unassign Floating IP
272 hetzner.hcloud.floating_ip:
273 name: "{{ hcloud_floating_ip_name }}"
274 type: ipv4
275 home_location: "{{ hcloud_location_name }}"
276 register: floatingIP
277 - name: verify test unassign Floating IP
278 assert:
279 that:
280 - floatingIP is changed
281 - floatingIP.hcloud_floating_ip.server != main_server.hcloud_server.name
282
283 - name: test unassign Floating IP idempotency
284 hetzner.hcloud.floating_ip:
285 name: "{{ hcloud_floating_ip_name }}"
286 type: ipv4
287 home_location: "{{ hcloud_location_name }}"
288 register: floatingIP
289 - name: verify test unassign Floating IPidempotency
290 assert:
291 that:
292 - floatingIP is not changed
293
294 - name: test assign Floating IP again
295 hetzner.hcloud.floating_ip:
296 name: "{{ hcloud_floating_ip_name }}"
297 type: ipv4
298 server: "{{ main_server.hcloud_server.name }}"
299 register: floatingIP
300 - name: verify test assign Floating IP again
301 assert:
302 that:
303 - floatingIP is changed
304 - floatingIP.hcloud_floating_ip.server == main_server.hcloud_server.name
305
306 - name: test already assigned Floating IP assign without force
307 hetzner.hcloud.floating_ip:
308 name: "{{ hcloud_floating_ip_name }}"
309 type: ipv4
310 server: "{{ main_server2.hcloud_server.name }}"
311 register: floatingIP
312 - name: verify test already assigned Floating IP assign without force
313 assert:
314 that:
315 - floatingIP is not changed
316 - floatingIP.hcloud_floating_ip.server == main_server.hcloud_server.name
317
318 - name: test already assigned Floating IP assign with force
319 hetzner.hcloud.floating_ip:
320 name: "{{ hcloud_floating_ip_name }}"
321 type: ipv4
322 force: true
323 server: "{{ main_server2.hcloud_server.name }}"
324 register: floatingIP
325 - name: verify test already assigned Floating IP assign with force
326 assert:
327 that:
328 - floatingIP is changed
329 - floatingIP.hcloud_floating_ip.server == main_server2.hcloud_server.name
330
331 - name: test update Floating IP delete protection
332 hetzner.hcloud.floating_ip:
333 name: "{{ hcloud_floating_ip_name }}"
334 type: ipv4
335 delete_protection: true
336 register: floatingIP
337 - name: verify update Floating IP delete protection
338 assert:
339 that:
340 - floatingIP is changed
341 - floatingIP.hcloud_floating_ip.delete_protection is sameas true
342
343 - name: test update Floating IP delete protection idempotency
344 hetzner.hcloud.floating_ip:
345 name: "{{ hcloud_floating_ip_name }}"
346 type: ipv4
347 delete_protection: true
348 register: floatingIP
349 - name: verify update Floating IP delete protection idempotency
350 assert:
351 that:
352 - floatingIP is not changed
353 - floatingIP.hcloud_floating_ip.delete_protection is sameas true
354
355 - name: test Floating IP without delete protection set to be idempotent
356 hetzner.hcloud.floating_ip:
357 name: "{{ hcloud_floating_ip_name }}"
358 type: ipv4
359 register: floatingIP
360 - name: verify Floating IP without delete protection set to be idempotent
361 assert:
362 that:
363 - floatingIP is not changed
364 - floatingIP.hcloud_floating_ip.delete_protection is sameas true
365
366 - name: test delete Floating IP fails if it is protected
367 hetzner.hcloud.floating_ip:
368 name: "{{ hcloud_floating_ip_name }}"
369 state: "absent"
370 register: result
371 ignore_errors: true
372 - name: verify test delete floating ip
373 assert:
374 that:
375 - result is failed
376 - result.failure.code == "protected"
377
378 - name: test update Floating IP delete protection
379 hetzner.hcloud.floating_ip:
380 name: "{{ hcloud_floating_ip_name }}"
381 type: ipv4
382 delete_protection: false
383 register: floatingIP
384 - name: verify update Floating IP delete protection
385 assert:
386 that:
387 - floatingIP is changed
388 - floatingIP.hcloud_floating_ip.delete_protection is sameas false
389
390 - name: test delete floating ip
391 hetzner.hcloud.floating_ip:
392 name: "{{ hcloud_floating_ip_name }}"
393 state: "absent"
394 register: result
395 - name: verify test delete floating ip
396 assert:
397 that:
398 - result is changed
399
400 - name: test create ipv6 floating ip
401 hetzner.hcloud.floating_ip:
402 name: "{{ hcloud_floating_ip_name }}"
403 type: ipv6
404 home_location: "{{ hcloud_location_name }}"
405 state: "present"
406 register: result
407 - name: verify test create ipv6 floating ip
408 assert:
409 that:
410 - result is changed
411
412 - name: test delete ipv6 floating ip
413 hetzner.hcloud.floating_ip:
414 name: "{{ hcloud_floating_ip_name }}"
415 state: "absent"
416 register: result
417 - name: verify test delete ipv6 floating ip
418 assert:
419 that:
420 - result is changed
421
422 - name: cleanup
423 hetzner.hcloud.server:
424 name: "{{ hcloud_server_name }}"
425 state: absent
426 register: result
427 - name: verify cleanup
428 assert:
429 that:
430 - result is changed
431 - name: cleanup another server
432 hetzner.hcloud.server:
433 name: "{{ main_server2.hcloud_server.name }}"
434 state: absent
435 register: result
436 - name: verify cleanup another server
437 assert:
438 that:
439 - result is changed
440
441 - name: test create Floating IP with delete protection
442 hetzner.hcloud.floating_ip:
443 name: "{{ hcloud_floating_ip_name }}"
444 type: ipv4
445 home_location: "{{ hcloud_location_name }}"
446 delete_protection: true
447 register: floatingIP
448 - name: verify create Floating IP with delete protection
449 assert:
450 that:
451 - floatingIP is changed
452 - floatingIP.hcloud_floating_ip.delete_protection is sameas true
453
454 - name: test delete Floating IP fails if it is protected
455 hetzner.hcloud.floating_ip:
456 name: "{{ hcloud_floating_ip_name }}"
457 state: "absent"
458 register: result
459 ignore_errors: true
460 - name: verify test delete floating ip
461 assert:
462 that:
463 - result is failed
464 - result.failure.code == "protected"
465
466 - name: test update Floating IP delete protection
467 hetzner.hcloud.floating_ip:
468 name: "{{ hcloud_floating_ip_name }}"
469 type: ipv4
470 delete_protection: false
471 register: floatingIP
472 - name: verify update Floating IP delete protection
473 assert:
474 that:
475 - floatingIP is changed
476 - floatingIP.hcloud_floating_ip.delete_protection is sameas false
477
478 - name: test delete floating ip
479 hetzner.hcloud.floating_ip:
480 name: "{{ hcloud_floating_ip_name }}"
481 state: "absent"
482 register: result
483 - name: verify test delete floating ip
484 assert:
485 that:
486 - result is changed