1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00
hetzner.hcloud/tests/integration/targets/ssh_key/tasks/test.yml
Jonas L f3d697c006
test: use shared variable for server type, image and location (#522)
##### SUMMARY

Use shared variables to store information about which server type, image
or location to use for our integrations tests.

- The location was changed from FSN to HEL.
- The image was changed from ubuntu-22.04 to debian-12.
2024-06-26 16:10:58 +02:00

147 lines
4 KiB
YAML

# 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
hetzner.hcloud.ssh_key:
name: "{{ hcloud_ssh_key_name }}"
register: result
ignore_errors: true
- 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
hetzner.hcloud.ssh_key:
name: "{{ hcloud_ssh_key_name }}"
public_key: "{{ test_ssh_keypair.public_key }}"
register: result
check_mode: true
- name: test create ssh key with check mode
assert:
that:
- result is changed
- name: test create ssh key
hetzner.hcloud.ssh_key:
name: "{{ hcloud_ssh_key_name }}"
public_key: "{{ test_ssh_keypair.public_key }}"
labels:
key: value
my-label: label
register: ssh_key
- name: verify create ssh key
assert:
that:
- ssh_key is changed
- ssh_key.hcloud_ssh_key.name == hcloud_ssh_key_name
- ssh_key.hcloud_ssh_key.public_key == test_ssh_keypair.public_key
- ssh_key.hcloud_ssh_key.labels.key == "value"
- name: test create ssh key idempotence
hetzner.hcloud.ssh_key:
name: "{{ hcloud_ssh_key_name }}"
public_key: "{{ test_ssh_keypair.public_key }}"
register: result
- name: verify create ssh key idempotence
assert:
that:
- result is not changed
- name: test update ssh key with check mode
hetzner.hcloud.ssh_key:
id: "{{ ssh_key.hcloud_ssh_key.id }}"
name: "changed-{{ hcloud_ssh_key_name }}"
register: result
check_mode: true
- name: test create ssh key with check mode
assert:
that:
- result is changed
- name: test update ssh key
hetzner.hcloud.ssh_key:
id: "{{ ssh_key.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
hetzner.hcloud.ssh_key:
id: "{{ ssh_key.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
hetzner.hcloud.ssh_key:
id: "{{ ssh_key.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
hetzner.hcloud.ssh_key:
id: "{{ ssh_key.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
hetzner.hcloud.server:
name: "{{ hcloud_server_name }}"
server_type: "{{ hcloud_server_type_name }}"
image: "{{ hcloud_image_name }}"
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: test fail cleanly on double created ssh key
hetzner.hcloud.ssh_key:
name: "{{ hcloud_ssh_key_name }}-other-name"
public_key: "{{ test_ssh_keypair.public_key }}"
register: result
ignore_errors: true
- name: verify failed correctly
assert:
that:
- result is failed
- result.failure.code == "uniqueness_error"
- result.msg == "SSH key with the same fingerprint already exists"
- name: test delete ssh key
hetzner.hcloud.ssh_key:
id: "{{ ssh_key.hcloud_ssh_key.id }}"
state: absent
register: result
- name: verify absent ssh_key
assert:
that:
- result is success