From 0166f079fc54070e2d18384f7ee06f3777f47295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=B6hring?= Date: Wed, 26 Oct 2022 11:49:29 +0200 Subject: [PATCH] fix hcloud_network_info failing without internet connectivity 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. --- plugins/modules/hcloud_network_info.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/modules/hcloud_network_info.py b/plugins/modules/hcloud_network_info.py index dd66b5e..81b186a 100644 --- a/plugins/modules/hcloud_network_info.py +++ b/plugins/modules/hcloud_network_info.py @@ -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),