mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Add hcloud_ssh_key module (#53550)
This commit is contained in:
committed by
René Moser
parent
ffa014e680
commit
3e02502056
2
test/integration/targets/hcloud_ssh_key/aliases
Normal file
2
test/integration/targets/hcloud_ssh_key/aliases
Normal file
@@ -0,0 +1,2 @@
|
||||
cloud/hcloud
|
||||
unsupported
|
||||
@@ -0,0 +1,8 @@
|
||||
# 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)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-integration"
|
||||
hcloud_ssh_key_name: "{{hcloud_prefix}}-integration"
|
||||
hcloud_ssh_key_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnaTPfKaX1QKcRLOfr34buVLh5FhJAThI9NYB0xNdXsMd4Y0zLyyCQzHbx4eWCVZxym/s6csWSeLaAhO1GOHeAw3hQFMqf1oTBx6Y8g0pKpeotKPa/PDSUzdZF9Lc+DadtpQd8kFVHAu1Kd3zoEUnk1u6kP7I4qu4Z/6F9qBDF+M3aobiPVxdS7GwaVRW3nZu+FcQDLiBiNOjuRDyjHcDfEUkoh2SOu25RrFtGPzFu5mGmBJwotKpWAocLGfHzyn/fAHxgw3jKZVH/t+XWQFnl82Ie8yE3Z1EZ7oDkNRqFQT9AdXEQOLycTTYTQMJZpgeFTv3sAo6lPRCusiFmmLcf ci@ansible.hetzner.cloud"
|
||||
hcloud_ssh_key_fingerprint: "56:89:c4:d6:a7:4a:79:82:f4:c2:58:9c:e1:d2:2d:4e"
|
||||
154
test/integration/targets/hcloud_ssh_key/tasks/main.yml
Normal file
154
test/integration/targets/hcloud_ssh_key/tasks/main.yml
Normal file
@@ -0,0 +1,154 @@
|
||||
# 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_ssh_key:
|
||||
fingerprint: "{{ hcloud_ssh_key_fingerprint }}"
|
||||
state: absent
|
||||
register: result
|
||||
- name: verify setup
|
||||
assert:
|
||||
that:
|
||||
- result is success
|
||||
- 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 server
|
||||
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: "{{ hcloud_ssh_key_public_key }}"
|
||||
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: "{{ hcloud_ssh_key_public_key }}"
|
||||
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 == "{{ hcloud_ssh_key_public_key }}"
|
||||
- sshKey.hcloud_ssh_key.fingerprint == "{{ hcloud_ssh_key_fingerprint }}"
|
||||
- sshKey.hcloud_ssh_key.labels.key == "value"
|
||||
|
||||
- name: test create ssh key idempotence
|
||||
hcloud_ssh_key:
|
||||
name: "{{ hcloud_ssh_key_name }}"
|
||||
public_key: "{{ hcloud_ssh_key_public_key }}"
|
||||
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-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-ssh-key-name"
|
||||
labels:
|
||||
key: value
|
||||
register: result
|
||||
- name: test update ssh key
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.hcloud_ssh_key.name == "changed-ssh-key-name"
|
||||
|
||||
- name: test update ssh key with same labels
|
||||
hcloud_ssh_key:
|
||||
id: "{{ sshKey.hcloud_ssh_key.id }}"
|
||||
name: "changed-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-ssh-key-name"
|
||||
labels:
|
||||
key: value
|
||||
test: 123
|
||||
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
|
||||
Reference in New Issue
Block a user