1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

fix hcloud_network_info failing without internet connectivity (#159)

This fixes the behavior if there is a server without direct internet
connectivity in the examined network.
Previously, the module would throw an AttributeError because
server.public_net.ipv4/ipv6 is None in this case. Now the None propagates
correctly.
This commit is contained in:
Konstantin Köhring 2022-11-07 13:59:21 +01:00 committed by GitHub
parent a87c82d808
commit 5cc7c58ecf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -136,12 +136,12 @@ hcloud_network_info:
type: str
sample: cx11
ipv4_address:
description: Public IPv4 address of the server
description: Public IPv4 address of the server, None if not existing
returned: always
type: str
sample: 116.203.104.109
ipv6:
description: IPv6 network of the server
description: IPv6 network of the server, None if not existing
returned: always
type: str
sample: 2a01:4f8:1c1c:c140::/64
@ -220,11 +220,13 @@ class AnsibleHcloudNetworkInfo(Hcloud):
servers = []
for server in network.servers:
image = None if server.image is None else to_native(server.image.name)
ipv4_address = None if server.public_net.ipv4 is None else to_native(server.public_net.ipv4.ip)
ipv6 = None if server.public_net.ipv6 is None else to_native(server.public_net.ipv6.ip)
prepared_server = {
"id": to_native(server.id),
"name": to_native(server.name),
"ipv4_address": to_native(server.public_net.ipv4.ip),
"ipv6": to_native(server.public_net.ipv6.ip),
"ipv4_address": ipv4_address,
"ipv6": ipv6,
"image": image,
"server_type": to_native(server.server_type.name),
"datacenter": to_native(server.datacenter.name),