2019-03-11 15:42:49 +01:00
|
|
|
# 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
|
2019-04-10 15:16:10 +02:00
|
|
|
- name: verify fail test missing required parameters on create ssh_key
|
2019-03-11 15:42:49 +01:00
|
|
|
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 }}"
|
2019-04-10 15:16:10 +02:00
|
|
|
public_key: "{{ key_material }}"
|
2019-03-11 15:42:49 +01:00
|
|
|
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 }}"
|
2019-04-10 15:16:10 +02:00
|
|
|
public_key: "{{ key_material }}"
|
2019-03-11 15:42:49 +01:00
|
|
|
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 }}"
|
2019-04-10 15:16:10 +02:00
|
|
|
- sshKey.hcloud_ssh_key.public_key == "{{ key_material }}"
|
2019-03-11 15:42:49 +01:00
|
|
|
- sshKey.hcloud_ssh_key.labels.key == "value"
|
|
|
|
|
|
|
|
- name: test create ssh key idempotence
|
|
|
|
hcloud_ssh_key:
|
|
|
|
name: "{{ hcloud_ssh_key_name }}"
|
2019-04-10 15:16:10 +02:00
|
|
|
public_key: "{{ key_material }}"
|
2019-03-11 15:42:49 +01:00
|
|
|
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 }}"
|
2019-04-10 15:16:10 +02:00
|
|
|
name: "changed-{{ hcloud_ssh_key_name }}"
|
2019-03-11 15:42:49 +01:00
|
|
|
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 }}"
|
2019-04-10 15:16:10 +02:00
|
|
|
name: "changed-{{ hcloud_ssh_key_name }}"
|
2019-03-11 15:42:49 +01:00
|
|
|
labels:
|
|
|
|
key: value
|
|
|
|
register: result
|
|
|
|
- name: test update ssh key
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
2019-04-10 15:16:10 +02:00
|
|
|
- result.hcloud_ssh_key.name == "changed-{{ hcloud_ssh_key_name }}"
|
2019-03-11 15:42:49 +01:00
|
|
|
|
|
|
|
- name: test update ssh key with same labels
|
|
|
|
hcloud_ssh_key:
|
|
|
|
id: "{{ sshKey.hcloud_ssh_key.id }}"
|
2019-04-10 15:16:10 +02:00
|
|
|
name: "changed-{{ hcloud_ssh_key_name }}"
|
2019-03-11 15:42:49 +01:00
|
|
|
labels:
|
|
|
|
key: value
|
|
|
|
register: result
|
2019-04-10 15:16:10 +02:00
|
|
|
- name: test update ssh key with same labels
|
2019-03-11 15:42:49 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result is not changed
|
|
|
|
|
|
|
|
- name: test update ssh key with other labels
|
|
|
|
hcloud_ssh_key:
|
|
|
|
id: "{{ sshKey.hcloud_ssh_key.id }}"
|
2019-04-10 15:16:10 +02:00
|
|
|
name: "changed-{{ hcloud_ssh_key_name }}"
|
2019-03-11 15:42:49 +01:00
|
|
|
labels:
|
|
|
|
key: value
|
2019-05-14 18:54:48 +02:00
|
|
|
test: "val123"
|
2019-03-11 15:42:49 +01:00
|
|
|
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
|