1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-03 23:51:48 +00:00

feat: deprecated datacenter in inventory

This commit is contained in:
jo 2025-12-17 14:25:29 +01:00
parent 88ae76905a
commit 54029e1725
No known key found for this signature in database
GPG key ID: B2FEC9B22722B984
2 changed files with 44 additions and 12 deletions

View file

@ -171,9 +171,12 @@ plugin: hetzner.hcloud.hcloud
# hcloud_image_id: 114690387
# hcloud_image_name: "debian-12"
# hcloud_image_os_flavor: "debian"
## Datacenter
# hcloud_datacenter: "hel1-dc2"
## Location
# hcloud_location: "hel1"
# # The hcloud_datacenter variable is deprecated and will be removed after 1 July 2026.
# # Please use the hcloud_location variable instead.
# # See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters.
# hcloud_datacenter: "hel1-dc2"
## Network
# hcloud_ipv4: "65.109.140.95" # Value is optional!
# hcloud_ipv6: "2a01:4f9:c011:b83f::1" # Value is optional!
@ -185,10 +188,11 @@ plugin: hetzner.hcloud.hcloud
# name: "my-private-network"
# ip: "10.0.0.3"
#
hostname: "my-prefix-{{ hcloud_datacenter }}-{{ hcloud_name }}-{{ hcloud_server_type }}"
hostname: "my-prefix-{{ hcloud_location }}-{{ hcloud_name }}-{{ hcloud_server_type }}"
"""
import sys
import warnings
from ipaddress import IPv6Network
from ansible.errors import AnsibleError
@ -230,7 +234,7 @@ if sys.version_info >= (3, 11):
architecture: str
# Datacenter
datacenter: str
datacenter: str # Deprecated!
location: str
# Labels
@ -322,7 +326,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
if self.get_option("locations"):
locations: list[str] = self.get_option("locations")
servers = [s for s in servers if s.datacenter.location.name in locations]
servers = [s for s in servers if s.location.name in locations]
if self.get_option("types"):
server_types: list[str] = self.get_option("types")
@ -365,9 +369,16 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
server_dict["private_ipv4"] = private_net.ip
break
# Datacenter
server_dict["datacenter"] = server.datacenter.name
server_dict["location"] = server.datacenter.location.name
# Location
server_dict["location"] = server.location.name
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=DeprecationWarning)
self.display.warning(
"The `hcloud_datacenter` variable is deprecated and will be removed "
"after 1 July 2026. Please use the `hcloud_location` variable instead. "
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters."
)
server_dict["datacenter"] = server.datacenter and server.datacenter.name
# Image
if server.image is not None:

View file

@ -33,18 +33,39 @@ def test_build_inventory_server():
"blocked": False,
"dns_ptr": "static.1.0.0.127.clients.your-server.de",
},
"ipv6": {"id": 56583279, "ip": "2001:db8::/64", "blocked": False, "dns_ptr": []},
"ipv6": {
"id": 56583279,
"ip": "2001:db8::/64",
"blocked": False,
"dns_ptr": [],
},
"floating_ips": [],
"firewalls": [],
},
"private_net": [],
"server_type": {"id": 109, "name": "cpx22", "architecture": "x86"},
"server_type": {
"id": 109,
"name": "cpx22",
"architecture": "x86",
},
"location": {
"id": 3,
"name": "hel1",
},
"datacenter": {
"id": 3,
"name": "hel1-dc2",
"location": {"id": 3, "name": "hel1"},
"location": {
"id": 3,
"name": "hel1",
},
},
"image": {
"id": 114690387,
"name": "debian-12",
"os_flavor": "debian",
"os_version": "12",
},
"image": {"id": 114690387, "name": "debian-12", "os_flavor": "debian", "os_version": "12"},
},
)
# pylint: disable=protected-access