Debian Codegraph @

ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/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: test missing required parameters on create ssh_key
5 hetzner.hcloud.ssh_key:
6 name: "{{ hcloud_ssh_key_name }}"
7 register: result
8 ignore_errors: true
9 - name: verify fail test missing required parameters on create ssh_key
10 assert:
11 that:
12 - result is failed
13 - 'result.msg == "missing required arguments: public_key"'
14
15 - name: test create ssh key with check mode
16 hetzner.hcloud.ssh_key:
17 name: "{{ hcloud_ssh_key_name }}"
18 public_key: "{{ test_ssh_keypair.public_key }}"
19 register: result
20 check_mode: true
21 - name: test create ssh key with check mode
22 assert:
23 that:
24 - result is changed
25
26 - name: test create ssh key
27 hetzner.hcloud.ssh_key:
28 name: "{{ hcloud_ssh_key_name }}"
29 public_key: "{{ test_ssh_keypair.public_key }}"
30 labels:
31 key: value
32 my-label: label
33 register: ssh_key
34 - name: verify create ssh key
35 assert:
36 that:
37 - ssh_key is changed
38 - ssh_key.hcloud_ssh_key.name == hcloud_ssh_key_name
39 - ssh_key.hcloud_ssh_key.public_key == test_ssh_keypair.public_key
40 - ssh_key.hcloud_ssh_key.labels.key == "value"
41
42 - name: test create ssh key idempotence
43 hetzner.hcloud.ssh_key:
44 name: "{{ hcloud_ssh_key_name }}"
45 public_key: "{{ test_ssh_keypair.public_key }}"
46 register: result
47 - name: verify create ssh key idempotence
48 assert:
49 that:
50 - result is not changed
51
52 - name: test update ssh key with check mode
53 hetzner.hcloud.ssh_key:
54 id: "{{ ssh_key.hcloud_ssh_key.id }}"
55 name: "changed-{{ hcloud_ssh_key_name }}"
56 register: result
57 check_mode: true
58 - name: test create ssh key with check mode
59 assert:
60 that:
61 - result is changed
62
63 - name: test update ssh key
64 hetzner.hcloud.ssh_key:
65 id: "{{ ssh_key.hcloud_ssh_key.id }}"
66 name: "changed-{{ hcloud_ssh_key_name }}"
67 labels:
68 key: value
69 register: result
70 - name: test update ssh key
71 assert:
72 that:
73 - result is changed
74 - result.hcloud_ssh_key.name == "changed-" + hcloud_ssh_key_name
75
76 - name: test update ssh key with same labels
77 hetzner.hcloud.ssh_key:
78 id: "{{ ssh_key.hcloud_ssh_key.id }}"
79 name: "changed-{{ hcloud_ssh_key_name }}"
80 labels:
81 key: value
82 register: result
83 - name: test update ssh key with same labels
84 assert:
85 that:
86 - result is not changed
87
88 - name: test update ssh key with other labels
89 hetzner.hcloud.ssh_key:
90 id: "{{ ssh_key.hcloud_ssh_key.id }}"
91 name: "changed-{{ hcloud_ssh_key_name }}"
92 labels:
93 key: value
94 test: "val123"
95 register: result
96 - name: test update ssh key with other labels
97 assert:
98 that:
99 - result is changed
100
101 - name: test rename ssh key
102 hetzner.hcloud.ssh_key:
103 id: "{{ ssh_key.hcloud_ssh_key.id }}"
104 name: "{{ hcloud_ssh_key_name }}"
105 register: result
106 - name: test rename ssh key
107 assert:
108 that:
109 - result is changed
110 - result.hcloud_ssh_key.name == hcloud_ssh_key_name
111
112 - name: test create server with ssh key
113 hetzner.hcloud.server:
114 name: "{{ hcloud_server_name }}"
115 server_type: "{{ hcloud_server_type_name }}"
116 image: "{{ hcloud_image_name }}"
117 location: "{{ hcloud_location_name }}"
118 ssh_keys:
119 - "{{ hcloud_ssh_key_name }}"
120 state: started
121 register: main_server
122 - name: verify create server with ssh key
123 assert:
124 that:
125 - main_server is changed
126
127 - name: test fail cleanly on double created ssh key
128 hetzner.hcloud.ssh_key:
129 name: "{{ hcloud_ssh_key_name }}-other-name"
130 public_key: "{{ test_ssh_keypair.public_key }}"
131 register: result
132 ignore_errors: true
133 - name: verify failed correctly
134 assert:
135 that:
136 - result is failed
137 - result.failure.code == "uniqueness_error"
138
139 - name: test update public key warning
140 hetzner.hcloud.ssh_key:
141 name: "{{ hcloud_ssh_key_name }}"
142 public_key: "{{ test_ssh_keypair2.public_key }}"
143 register: result
144 - name: verify update public key warning
145 assert:
146 that:
147 - result is not changed
148 - result.hcloud_ssh_key.name == hcloud_ssh_key_name
149 - result.hcloud_ssh_key.public_key == test_ssh_keypair.public_key
150
151 - name: test update public key with force
152 hetzner.hcloud.ssh_key:
153 name: "{{ hcloud_ssh_key_name }}"
154 public_key: "{{ test_ssh_keypair2.public_key }}"
155 force: true
156 register: result
157 - name: verify update public key with force
158 assert:
159 that:
160 - result is changed
161 - result.hcloud_ssh_key.name == hcloud_ssh_key_name
162 - result.hcloud_ssh_key.public_key == test_ssh_keypair2.public_key
163
164 - name: test update public key with force idempotence
165 hetzner.hcloud.ssh_key:
166 name: "{{ hcloud_ssh_key_name }}"
167 public_key: "{{ test_ssh_keypair2.public_key }}"
168 force: true
169 register: result
170 - name: verify update public key with force idempotence
171 assert:
172 that:
173 - result is not changed
174
175 - name: test delete ssh key
176 hetzner.hcloud.ssh_key:
177 name: "{{ hcloud_ssh_key_name }}"
178 state: absent
179 register: result
180 - name: verify absent ssh_key
181 assert:
182 that:
183 - result is success