1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00
hetzner.hcloud/examples/server-assign-to-subnetwork.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

54 lines
1.3 KiB
YAML

---
- name: Demonstrate assigning a server to a specific subnetwork
hosts: localhost
connection: local
vars:
servers:
- name: my-server1
subnetwork: 10.0.2.0/24
- name: my-server2
subnetwork: 10.0.1.0/24
- name: my-server3
subnetwork: 10.0.2.0/24
tasks:
- name: Create a network
hetzner.hcloud.network:
name: my-network
ip_range: 10.0.0.0/8
state: present
- name: Create first subnetwork
hetzner.hcloud.subnetwork:
network: my-network
ip_range: 10.0.1.0/24
network_zone: eu-central
type: cloud
state: present
- name: Create second subnetwork
hetzner.hcloud.subnetwork:
network: my-network
ip_range: 10.0.2.0/24
network_zone: eu-central
type: cloud
state: present
- name: Create servers
hetzner.hcloud.server:
name: "{{ item.name }}"
server_type: cpx22
image: debian-12
state: present
loop: "{{ servers }}"
- name: Attach servers to subnetworks
hetzner.hcloud.server_network:
network: my-network
server: "{{ item.name }}"
ip: "{{ item.subnetwork | ansible.utils.nthhost(index+1) }}"
state: present
loop: "{{ servers }}"
loop_control:
index_var: index