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

loadbalancer_: improve error handlings (#138)

* loadbalancer_: improve error handlings

* streamline a bit to make ansible 2.9 pass

* handle race condition
This commit is contained in:
René Moser 2022-06-20 06:26:26 +02:00 committed by GitHub
parent a0a5da3f46
commit 1d568f3ac7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 99 additions and 10 deletions

View file

@ -177,9 +177,19 @@ class AnsibleHcloudLoadBalancerTarget(Hcloud):
def _get_load_balancer_and_target(self):
try:
self.hcloud_load_balancer = self.client.load_balancers.get_by_name(self.module.params.get("load_balancer"))
load_balancer_name = self.module.params.get("load_balancer")
self.hcloud_load_balancer = self.client.load_balancers.get_by_name(
load_balancer_name
)
if not self.hcloud_load_balancer:
self.module.fail_json(msg="Load balancer does not exist: %s" % load_balancer_name)
if self.module.params.get("type") == "server":
self.hcloud_server = self.client.servers.get_by_name(self.module.params.get("server"))
server_name = self.module.params.get("server")
self.hcloud_server = self.client.servers.get_by_name(server_name)
if not self.hcloud_server:
self.module.fail_json(msg="Server not found: %s" % server_name)
self.hcloud_load_balancer_target = None
except Exception as e:
self.module.fail_json(msg=e.message)