1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-03 23:51:48 +00:00
hetzner.hcloud/examples/server-with-firewall.yml
Julian Tölle 59c539c48b
docs: update deprecated server types (#718)
The CX Gen 2 and CPX Gen 1 types are deprecated and will be removed from
the API at the end of the year. This replaces all usages in our docs, so
users do not have to figure it out themselves.

Changelog Entry: https://docs.hetzner.cloud/changelog#2025-10-16-server-types-deprecated


Co-authored-by: Petteri Räty <github@petteriraty.eu>
2025-10-28 13:45:41 +01:00

62 lines
1.5 KiB
YAML

---
- 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: cpx22
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 }}"