summaryrefslogtreecommitdiff
path: root/test/integration/targets/hcloud_ssh_key/tasks/main.yml
blob: baaadd4db46dbdfc70b2284ef0527e787d369924 (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
# 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: test missing required parameters on create ssh_key
  hcloud_ssh_key:
    name: "{{ hcloud_ssh_key_name }}"
  register: result
  ignore_errors: yes
- name: verify fail test missing required parameters on create ssh_key
  assert:
    that:
      - result is failed
      - 'result.msg == "missing required arguments: public_key"'

- name: test create ssh key with check mode
  hcloud_ssh_key:
    name: "{{ hcloud_ssh_key_name }}"
    public_key: "{{ key_material }}"
  register: result
  check_mode: yes
- name: test create ssh key with check mode
  assert:
    that:
      - result is changed

- name: test create ssh key
  hcloud_ssh_key:
    name: "{{ hcloud_ssh_key_name }}"
    public_key: "{{ key_material }}"
    labels:
      key: value
      my-label: label
  register: sshKey
- name: verify create ssh key
  assert:
    that:
      - sshKey is changed
      - sshKey.hcloud_ssh_key.name == "{{ hcloud_ssh_key_name }}"
      - sshKey.hcloud_ssh_key.public_key ==  "{{ key_material }}"
      - sshKey.hcloud_ssh_key.labels.key == "value"

- name: test create ssh key idempotence
  hcloud_ssh_key:
    name: "{{ hcloud_ssh_key_name }}"
    public_key: "{{ key_material }}"
  register: result
- name: verify create ssh key idempotence
  assert:
    that:
      - result is not changed

- name: test update ssh key with check mode
  hcloud_ssh_key:
    id: "{{ sshKey.hcloud_ssh_key.id }}"
    name: "changed-{{ hcloud_ssh_key_name }}"
  register: result
  check_mode: yes
- name: test create ssh key with check mode
  assert:
    that:
      - result is changed

- name: test update ssh key
  hcloud_ssh_key:
    id: "{{ sshKey.hcloud_ssh_key.id }}"
    name: "changed-{{ hcloud_ssh_key_name }}"
    labels:
      key: value
  register: result
- name: test update ssh key
  assert:
    that:
      - result is changed
      - result.hcloud_ssh_key.name == "changed-{{ hcloud_ssh_key_name }}"

- name: test update ssh key with same labels
  hcloud_ssh_key:
    id: "{{ sshKey.hcloud_ssh_key.id }}"
    name: "changed-{{ hcloud_ssh_key_name }}"
    labels:
      key: value
  register: result
- name: test update ssh key with same labels
  assert:
    that:
      - result is not changed

- name: test update ssh key with other labels
  hcloud_ssh_key:
    id: "{{ sshKey.hcloud_ssh_key.id }}"
    name: "changed-{{ hcloud_ssh_key_name }}"
    labels:
      key: value
      test: "val123"
  register: result
- name: test update ssh key  with other labels
  assert:
    that:
      - result is changed

- name: test rename ssh key
  hcloud_ssh_key:
    id: "{{ sshKey.hcloud_ssh_key.id }}"
    name: "{{ hcloud_ssh_key_name }}"
  register: result
- name: test rename ssh key
  assert:
    that:
      - result is changed
      - result.hcloud_ssh_key.name == "{{ hcloud_ssh_key_name }}"

- name: test create server with ssh key
  hcloud_server:
    name: "{{ hcloud_server_name }}"
    server_type: cx11
    image: "ubuntu-18.04"
    ssh_keys:
      - "{{ hcloud_ssh_key_name }}"
    state: started
  register: main_server
- name: verify create server with ssh key
  assert:
    that:
      - main_server is changed

- name: absent ssh key
  hcloud_ssh_key:
    id: "{{ sshKey.hcloud_ssh_key.id }}"
    state: absent
  register: result
- name: verify absent server
  assert:
    that:
      - result is success

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