summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/incidental_hcloud_server/tasks/main.yml
blob: 31c7ad97e0b729085069a9d46e1d090a6be92946 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# Copyright: (c) 2019, Hetzner Cloud GmbH <info@hetzner-cloud.de>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- name: setup
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: absent
  register: result
- name: verify setup
  assert:
    that:
    - result is success
- name: test missing required parameters on create server
  hcloud_server:
    name: "{{ hcloud_server_name }}"
  register: result
  ignore_errors: yes
- name: verify fail test missing required parameters on create server
  assert:
    that:
      - result is failed
      - 'result.msg == "missing required arguments: server_type, image"'

- name: test create server with check mode
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    server_type: cx11
    image: ubuntu-18.04
    state: present
  register: result
  check_mode: yes
- name: test create server server
  assert:
    that:
      - result is changed

- name: test create server
  hcloud_server:
    name: "{{ hcloud_server_name}}"
    server_type: cx11
    image: ubuntu-18.04
    state: started
  register: main_server
- name: verify create server
  assert:
    that:
      - main_server is changed
      - main_server.hcloud_server.name == "{{ hcloud_server_name }}"
      - main_server.hcloud_server.server_type == "cx11"
      - main_server.hcloud_server.status == "running"
      - main_server.root_password != ""

- name: test create server idempotence
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: started
  register: result
- name: verify create server idempotence
  assert:
    that:
      - result is not changed

- name: test stop server with check mode
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: stopped
  register: result
  check_mode: yes
- name: verify stop server with check mode
  assert:
    that:
      - result is changed
      - result.hcloud_server.status == "running"

- name: test stop server
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: stopped
  register: result
- name: verify stop server
  assert:
    that:
      - result is changed
      - result.hcloud_server.status == "off"

- name: test start server with check mode
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: started
  register: result
  check_mode: true
- name: verify start server with check mode
  assert:
    that:
      - result is changed

- name: test start server
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: started
  register: result
- name: verify start server
  assert:
    that:
      - result is changed
      - result.hcloud_server.status == "running"

- name: test start server idempotence
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: started
  register: result
- name: verify start server idempotence
  assert:
    that:
      - result is not changed
      - result.hcloud_server.status == "running"

- name: test stop server by its id
  hcloud_server:
    id: "{{ main_server.hcloud_server.id }}"
    state: stopped
  register: result
- name: verify stop server by its id
  assert:
    that:
      - result is changed
      - result.hcloud_server.status == "off"

- name: test resize server running without force
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    server_type: "cx21"
    state: present
  register: result
  check_mode: true
- name: verify test resize server running without force
  assert:
    that:
      - result is changed
      - result.hcloud_server.server_type == "cx11"

- name: test resize server with check mode
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    server_type: "cx21"
    state: stopped
  register: result
  check_mode: true
- name: verify resize server with check mode
  assert:
    that:
      - result is changed

- name: test enable backups with check mode
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    backups: true
    state: stopped
  register: result
  check_mode: true
- name: verify enable backups with check mode
  assert:
    that:
      - result is changed

- name: test enable backups
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    backups: true
    state: stopped
  register: result
- name: verify enable backups
  assert:
    that:
      - result is changed
      - result.hcloud_server.backup_window != ""

- name: test enable backups idempotence
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    backups: true
    state: stopped
  register: result
- name: verify enable backups idempotence
  assert:
    that:
      - result is not changed
      - result.hcloud_server.backup_window != ""

- name: test rebuild server
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    image: ubuntu-18.04
    state: rebuild
  register: result_after_test
- name: verify rebuild server
  assert:
    that:
      - result_after_test is changed
      - result.hcloud_server.id == result_after_test.hcloud_server.id

- name: test rebuild server with check mode
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    image: ubuntu-18.04
    state: rebuild
  register: result_after_test
  check_mode: true
- name: verify rebuild server with check mode
  assert:
    that:
      - result_after_test is changed

- name: test update server protection booth protection arguments are required
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    delete_protection: true
    state: present
  register: result_after_test
  ignore_errors: true
- name: verify update server protection booth protection arguments are required
  assert:
    that:
      - result_after_test is failed
      - 'result_after_test.msg == "parameters are required together: delete_protection, rebuild_protection"'

- name: test update server protection fails if they are not the same
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    delete_protection: true
    rebuild_protection: false
    state: present
  register: result_after_test
  ignore_errors: true
- name: verify update server protection fails if they are not the same
  assert:
    that:
      - result_after_test is failed

- name: test update server protection
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    delete_protection: true
    rebuild_protection: true
    state: present
  register: result_after_test
  ignore_errors: true
- name: verify update server protection
  assert:
    that:
      - result_after_test is changed
      - result_after_test.hcloud_server.delete_protection is sameas true
      - result_after_test.hcloud_server.rebuild_protection is sameas true

- name: test server without protection set to be idempotent
  hcloud_server:
    name: "{{hcloud_server_name}}"
  register: result_after_test
- name: verify test server without protection set to be idempotent
  assert:
    that:
      - result_after_test is not changed
      - result_after_test.hcloud_server.delete_protection is sameas true
      - result_after_test.hcloud_server.rebuild_protection is sameas true

- name: test delete server fails if it is protected
  hcloud_server:
    name: "{{hcloud_server_name}}"
    state: absent
  ignore_errors: yes
  register: result
- name: verify delete server fails if it is protected
  assert:
    that:
      - result is failed
      - 'result.msg == "server deletion is protected"'

- name: test rebuild server fails if it is protected
  hcloud_server:
    name: "{{hcloud_server_name}}"
    image: ubuntu-18.04
    state: rebuild
  ignore_errors: yes
  register: result
- name: verify rebuild server fails if it is protected
  assert:
    that:
      - result is failed
      - 'result.msg == "server rebuild is protected"'

- name: test remove server protection
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    delete_protection: false
    rebuild_protection: false
    state: present
  register: result_after_test
  ignore_errors: true
- name: verify remove server protection
  assert:
    that:
      - result_after_test is changed
      - result_after_test.hcloud_server.delete_protection is sameas false
      - result_after_test.hcloud_server.rebuild_protection is sameas false

- name: absent server
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: absent
  register: result
- name: verify absent server
  assert:
    that:
    - result is success

- name: test create server with ssh key
  hcloud_server:
    name: "{{ hcloud_server_name}}"
    server_type: cx11
    image: "ubuntu-18.04"
    ssh_keys:
      - ci@ansible.hetzner.cloud
    state: started
  register: main_server
- name: verify create server with ssh key
  assert:
    that:
      - main_server is changed
      - main_server.hcloud_server.name == "{{ hcloud_server_name }}"
      - main_server.hcloud_server.server_type == "cx11"
      - main_server.hcloud_server.status == "running"
      - main_server.root_password != ""

- name: absent server
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: absent
  register: result
- name: verify absent server
  assert:
    that:
    - result is success

- name: test create server with rescue_mode
  hcloud_server:
    name: "{{ hcloud_server_name}}"
    server_type: cx11
    image: "ubuntu-18.04"
    ssh_keys:
      - ci@ansible.hetzner.cloud
    rescue_mode: "linux64"
    state: started
  register: main_server
- name: verify create server with rescue_mode
  assert:
    that:
      - main_server is changed
      - main_server.hcloud_server.name == "{{ hcloud_server_name }}"
      - main_server.hcloud_server.server_type == "cx11"
      - main_server.hcloud_server.status == "running"
      - main_server.root_password != ""
      - main_server.hcloud_server.rescue_enabled is sameas true

- name: absent server
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: absent
  register: result
- name: verify absent server
  assert:
    that:
    - result is success

- name: setup server
  hcloud_server:
    name: "{{ hcloud_server_name}}"
    server_type: cx11
    image: ubuntu-18.04
    state: started
  register: main_server
- name: verify setup server
  assert:
    that:
      - main_server is changed
      - main_server.hcloud_server.name == "{{ hcloud_server_name }}"
      - main_server.hcloud_server.server_type == "cx11"
      - main_server.hcloud_server.status == "running"
      - main_server.root_password != ""

- name: test activate rescue mode with check_mode
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    rescue_mode: "linux64"
    ssh_keys:
      - ci@ansible.hetzner.cloud
    state: present
  register: main_server
  check_mode: true
- name: verify activate rescue mode
  assert:
    that:
      - main_server is changed

- name: test activate rescue mode
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    rescue_mode: "linux64"
    ssh_keys:
      - ci@ansible.hetzner.cloud
    state: present
  register: main_server
- name: verify activate rescue mode
  assert:
    that:
      - main_server is changed
      - main_server.hcloud_server.rescue_enabled is sameas true

- name: test disable rescue mode
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    ssh_keys:
      - ci@ansible.hetzner.cloud
    state: present
  register: main_server
- name: verify activate rescue mode
  assert:
    that:
      - main_server is changed
      - main_server.hcloud_server.rescue_enabled is sameas false

- name: test activate rescue mode without ssh keys
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    rescue_mode: "linux64"
    state: present
  register: main_server
- name: verify activate rescue mode without ssh keys
  assert:
    that:
      - main_server is changed
      - main_server.hcloud_server.rescue_enabled is sameas true

- name: cleanup
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: absent
  register: result
- name: verify cleanup
  assert:
    that:
    - result is success

- name: test create server with labels
  hcloud_server:
    name: "{{ hcloud_server_name}}"
    server_type: cx11
    image: "ubuntu-18.04"
    ssh_keys:
      - ci@ansible.hetzner.cloud
    labels:
      key: value
      mylabel: "val123"
    state: started
  register: main_server
- name: verify create server with labels
  assert:
    that:
      - main_server is changed
      - main_server.hcloud_server.labels.key == "value"
      - main_server.hcloud_server.labels.mylabel == "val123"

- name: test update server with labels
  hcloud_server:
    name: "{{ hcloud_server_name}}"
    server_type: cx11
    image: "ubuntu-18.04"
    ssh_keys:
      - ci@ansible.hetzner.cloud
    labels:
      key: other
      mylabel: "val123"
    state: started
  register: main_server
- name: verify update server with labels
  assert:
    that:
      - main_server is changed
      - main_server.hcloud_server.labels.key == "other"
      - main_server.hcloud_server.labels.mylabel == "val123"

- name: test update server with labels in other order
  hcloud_server:
    name: "{{ hcloud_server_name}}"
    server_type: cx11
    image: "ubuntu-18.04"
    ssh_keys:
      - ci@ansible.hetzner.cloud
    labels:
      mylabel: "val123"
      key: other
    state: started
  register: main_server
- name: verify update server with labels in other order
  assert:
    that:
      - main_server is not changed

- name: cleanup with labels
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    state: absent
  register: result
- name: verify cleanup
  assert:
    that:
    - result is success