Skip to content

Commit

Permalink
create hcloud_image_info snapshots on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Sep 6, 2023
1 parent 7dec1e4 commit 1432845
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright: (c) 2019, Hetzner Cloud GmbH <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
hcloud_snapshot_id: 10164049
hcloud_snapshot_name: always-there-snapshot
hcloud_server_name: "{{ hcloud_ns }}"
hcloud_snapshot_name: "{{ hcloud_ns }}"
hcloud_image_name: ubuntu-22.04
3 changes: 3 additions & 0 deletions tests/integration/targets/hcloud_image_info/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- setup_hcloud_cli
5 changes: 5 additions & 0 deletions tests/integration/targets/hcloud_image_info/tasks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Cleanup test_server
hetzner.hcloud.hcloud_server:
name: "{{ hcloud_server_name }}"
state: absent
24 changes: 24 additions & 0 deletions tests/integration/targets/hcloud_image_info/tasks/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: Create test_server
hetzner.hcloud.hcloud_server:
name: "{{ hcloud_server_name }}"
server_type: cx11
image: ubuntu-22.04
state: stopped
register: test_server

- name: Create test_snapshot
ansible.builtin.script:
cmd: >
{{ hcloud_cli_path }} server create-image
--type snapshot
--description "{{ hcloud_snapshot_name }}"
--label key=value
"{{ test_server.hcloud_server.id }}"
| awk '{print $2}'
register: test_snapshot
delegate_to: localhost

- name: Set test_snapshot_id
ansible.builtin.set_fact:
test_snapshot_id: "{{ test_snapshot.stdout_lines[0] }}"
4 changes: 2 additions & 2 deletions tests/integration/targets/hcloud_image_info/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

- name: Gather hcloud_image_info with correct id
hetzner.hcloud.hcloud_image_info:
id: "{{ hcloud_snapshot_id }}"
id: "{{ test_snapshot_id }}"
type: snapshot
register: result
- name: Verify hcloud_image_info with correct id
Expand All @@ -40,7 +40,7 @@

- name: Gather hcloud_image_info with wrong id
hetzner.hcloud.hcloud_image_info:
id: "{{ hcloud_snapshot_id }}4321"
id: "{{ test_snapshot_id }}4321"
type: snapshot
ignore_errors: true
register: result
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/targets/setup_hcloud_cli/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Install hcloud cli
delegate_to: localhost
block:
- name: Create temporary file for hcloud_cli_path
ansible.builtin.tempfile:
state: directory
register: _tmp_hcloud_cli

- name: Download hcloud cli from Github releases
ansible.builtin.unarchive:
src: https://github.com/hetznercloud/cli/releases/download/v1.37.0/hcloud-linux-amd64.tar.gz
dest: "{{ _tmp_hcloud_cli.path }}"
remote_src: true
extra_opts: [hcloud]

- name: Set hcloud_cli_path
ansible.builtin.set_fact:
hcloud_cli_path: "{{ _tmp_hcloud_cli.path }}/hcloud"

0 comments on commit 1432845

Please sign in to comment.