From 7fec0b69a082aaeec72fee0612766aa42f6b1b4d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 18 Apr 2024 07:52:35 +0200 Subject: Merging upstream version 9.4.0+dfsg. Signed-off-by: Daniel Baumann --- .../hetzner/hcloud/examples/inventory.hcloud.yml | 7 +++ .../hcloud/examples/server-with-firewall.yml | 62 ++++++++++++++++++++++ .../examples/server-with-private-ip-only.yml | 50 +++++++++++++++++ .../hcloud/examples/use-module-defaults-group.yml | 27 ++++++++++ .../hcloud/examples/use-refresh-inventory.yml | 35 ++++++++++++ 5 files changed, 181 insertions(+) create mode 100644 ansible_collections/hetzner/hcloud/examples/inventory.hcloud.yml create mode 100644 ansible_collections/hetzner/hcloud/examples/server-with-firewall.yml create mode 100644 ansible_collections/hetzner/hcloud/examples/server-with-private-ip-only.yml create mode 100644 ansible_collections/hetzner/hcloud/examples/use-module-defaults-group.yml create mode 100644 ansible_collections/hetzner/hcloud/examples/use-refresh-inventory.yml (limited to 'ansible_collections/hetzner/hcloud/examples') diff --git a/ansible_collections/hetzner/hcloud/examples/inventory.hcloud.yml b/ansible_collections/hetzner/hcloud/examples/inventory.hcloud.yml new file mode 100644 index 000000000..6a67e2836 --- /dev/null +++ b/ansible_collections/hetzner/hcloud/examples/inventory.hcloud.yml @@ -0,0 +1,7 @@ +# You can list the hosts using: +# ansible-inventory --list -i examples/inventory.hcloud.yml --extra-vars=network_name=my-network + +plugin: hetzner.hcloud.hcloud + +network: "{{ network_name }}" +status: [running] diff --git a/ansible_collections/hetzner/hcloud/examples/server-with-firewall.yml b/ansible_collections/hetzner/hcloud/examples/server-with-firewall.yml new file mode 100644 index 000000000..0e5709676 --- /dev/null +++ b/ansible_collections/hetzner/hcloud/examples/server-with-firewall.yml @@ -0,0 +1,62 @@ +--- +- name: Demonstrate creating servers with a firewall + hosts: localhost + connection: local + + vars: + servers: + - name: my-server1 + - name: my-server2 + + tasks: + - name: Create firewall + hetzner.hcloud.firewall: + name: my-firewall + rules: + - description: allow icmp from everywhere + direction: in + protocol: icmp + source_ips: + - 0.0.0.0/0 + - ::/0 + - description: allow ssh from everywhere + direction: in + protocol: tcp + port: 22 + source_ips: + - 0.0.0.0/0 + - ::/0 + state: present + + - name: Create servers + hetzner.hcloud.server: + name: "{{ item.name }}" + server_type: cx11 + image: debian-12 + labels: + kind: runners + state: started + loop: "{{ servers }}" + + - name: Apply firewall to resources using label selectors + hetzner.hcloud.firewall_resource: + firewall: my-firewall + label_selectors: [kind=runners] + state: present + + - name: Apply firewall to individual servers + hetzner.hcloud.firewall_resource: + firewall: my-firewall + servers: "{{ servers | map(attribute='name') }}" + state: present + + - name: Delete firewall + hetzner.hcloud.firewall: + name: my-firewall + state: absent + + - name: Delete servers + hetzner.hcloud.server: + name: "{{ item.name }}" + state: absent + loop: "{{ servers }}" diff --git a/ansible_collections/hetzner/hcloud/examples/server-with-private-ip-only.yml b/ansible_collections/hetzner/hcloud/examples/server-with-private-ip-only.yml new file mode 100644 index 000000000..67cf47e51 --- /dev/null +++ b/ansible_collections/hetzner/hcloud/examples/server-with-private-ip-only.yml @@ -0,0 +1,50 @@ +--- +- name: Demonstrate creating a server that only has a private ip + hosts: localhost + connection: local + + vars: + servers: + - name: my-server1 + private_ip: 10.0.0.2 + - name: my-server2 + private_ip: 10.0.0.3 + + tasks: + - name: Create a network + hetzner.hcloud.network: + name: my-network + ip_range: 10.0.0.0/8 + state: present + + - name: Create a subnetwork + hetzner.hcloud.subnetwork: + network: my-network + ip_range: 10.0.0.0/16 + network_zone: eu-central + type: cloud + state: present + + - name: Create servers without public IPs + hetzner.hcloud.server: + name: "{{ item.name }}" + server_type: cx11 + image: debian-12 + enable_ipv4: false + enable_ipv6: false + state: stopped # A server without networking cannot be started! + loop: "{{ servers }}" + + - name: Attach private IP to servers + hetzner.hcloud.server_network: + network: my-network + server: "{{ item.name }}" + ip: "{{ item.private_ip }}" + state: present + loop: "{{ servers }}" + + - name: Start servers + hetzner.hcloud.server: + name: "{{ item.name }}" + state: started + loop: "{{ servers }}" diff --git a/ansible_collections/hetzner/hcloud/examples/use-module-defaults-group.yml b/ansible_collections/hetzner/hcloud/examples/use-module-defaults-group.yml new file mode 100644 index 000000000..f3de9adac --- /dev/null +++ b/ansible_collections/hetzner/hcloud/examples/use-module-defaults-group.yml @@ -0,0 +1,27 @@ +--- +- name: Demonstrate the usage of the 'hetzner.hcloud.all' module_defaults group + hosts: localhost + connection: local + + module_defaults: + group/hetzner.hcloud.all: + api_token: LRK9DAWQ1ZAEFSrCNEEzLCUwhYX1U3g7wMg4dTlkkDC96fyDuyJ39nVbVjCKSDfj + + tasks: + - name: Create a volume + hetzner.hcloud.volume: + name: my-volume + location: fsn1 + size: 100 + state: present + register: volume + + - name: Create a server + hetzner.hcloud.server: + name: my-server + server_type: cx11 + image: debian-12 + location: fsn1 + volumes: + - "{{ volume.hcloud_volume.id }}" + state: present diff --git a/ansible_collections/hetzner/hcloud/examples/use-refresh-inventory.yml b/ansible_collections/hetzner/hcloud/examples/use-refresh-inventory.yml new file mode 100644 index 000000000..fd4c351b6 --- /dev/null +++ b/ansible_collections/hetzner/hcloud/examples/use-refresh-inventory.yml @@ -0,0 +1,35 @@ +--- +- name: Demonstrate the usage of 'refresh_inventory' + hosts: localhost + connection: local + + tasks: + - name: Print hostvars + ansible.builtin.debug: + var: hostvars + + - name: Create new server + hetzner.hcloud.server: + name: my-server + server_type: cx11 + image: debian-12 + + - name: Refresh inventory + ansible.builtin.meta: refresh_inventory + + - name: Run tests + block: + - name: Print updated inventory + ansible.builtin.debug: + var: hostvars + + - name: Verify hostvars is not empty + ansible.builtin.assert: + that: + - hostvars != {} + + always: + - name: Cleanup server + hetzner.hcloud.server: + name: my-server + state: absent -- cgit v1.2.3