hetzner.hcloud
hetzner.hcloud copied to clipboard
hcloud_load_balancer_info don't return status
SUMMARY
I would like to get the HEALTH STATUS of a loadbalencer to ensure that everything is fine before i continue my ansible run.
ISSUE TYPE
- Bug Report
COMPONENT NAME
hetzner.hcloud.load_balancer_info
ANSIBLE VERSION
ansible [core 2.16.3]
python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/home/.../git/ext-infra/venv/bin/python3)
jinja version = 3.1.2
libyaml = True
COLLECTION VERSION
Collection Version
-------------- -------
hetzner.hcloud 2.4.1
STEPS TO REPRODUCE
---
- name: Get LB Status
hosts: localhost
tags: lb
tasks:
- name: Create test-lb
hetzner.hcloud.load_balancer:
name: test-lb
load_balancer_type: lb11
location: nbg1
api_token: "{{ hcloud_api_token }}"
- name: Add service to test-lb
hetzner.hcloud.load_balancer_service:
load_balancer: test-lb
protocol: tcp
listen_port: 80
destination_port: 80
proxyprotocol: yes
api_token: "{{ hcloud_api_token }}"
- name: Add Balancer target
hetzner.hcloud.load_balancer_target:
type: label_selector
load_balancer: test-lb
label_selector: pool=test-lb
api_token: "{{ hcloud_api_token }}"
- name: Gather hcloud load_balancer infos
hetzner.hcloud.load_balancer_info:
name: test-lb
api_token: "{{ hcloud_api_token }}"
register: output
- name: Print the gathered infos
ansible.builtin.debug:
var: output.hcloud_load_balancer_info
EXPECTED RESULTS
some sort of status like "running" in output.hcloud_load_balancer_info https://docs.ansible.com/ansible/latest/collections/hetzner/hcloud/load_balancer_info_module.html#return-hcloud_load_balancer_info/status
ACTUAL RESULTS
ok: [localhost] => {
"output.hcloud_load_balancer_info": [
{
"delete_protection": false,
"disable_public_interface": false,
"id": "1706869",
"ipv4_address": "some-ipv4",
"ipv6_address": "some-ipv6",
"labels": {},
"load_balancer_type": "lb11",
"location": "nbg1",
"name": "test-lb",
"private_ipv4_address": null,
"services": [
{
"destination_port": 80,
"health_check": {
"interval": 15,
"port": 80,
"protocol": "tcp",
"retries": 3,
"timeout": 10
},
"http": null,
"listen_port": 80,
"protocol": "tcp",
"proxyprotocol": true
}
],
"targets": [
{
"label_selector": "pool=test-lb",
"type": "label_selector",
"use_private_ip": false
}
]
}
]
}
Hi,
The returned status
from the documentation shouldn't exist, I will remove it from the docs. We could compute our own value for this status field, but I am not sure if this is ideal.
There is a health_status
object for the targets https://docs.ansible.com/ansible/latest/collections/hetzner/hcloud/load_balancer_info_module.html#return-hcloud_load_balancer_info/targets/health_status, you may use this value to check the status of your load balancer.
Note that:
- the health status is only present for IP or server targets.
- the health status might time some time to be returned by the API.
See https://docs.hetzner.cloud/#load-balancers-get-a-load-balancer
in my example output there is also no "health_status object for the targets".
This is because the target is of type label_selector
, as stated above, the health status is only present on IP or server target types. You can find the documentation for the health status field here https://docs.hetzner.cloud/#load-balancers-get-a-load-balancer
Thanks a i realized this a few minutes before and delete my comment ;-)
Ok so there is no way to verify the overall Health of a loadbalencer with label_selector targets?
I just tested this myself, and the "resolved" targets from the label_selector
target, do have a health status. This is not clear in the documentation, I'll try to improve this, and I'll get back to you with a solution.
The API response looks like the following:
{
"targets": [
{
"type": "label_selector",
"use_private_ip": false,
"label_selector": {
"selector": "test=ok"
},
"targets": [
{
"type": "server",
"server": {
"id": 43962499
},
"health_status": [
{
"listen_port": 80,
"status": "unhealthy"
}
],
"use_private_ip": false
}
]
}
]
}
This issue has been marked as stale because it has not had recent activity. The bot will close the issue if no further action occurs.
not stale
@EHEX-schildt Since I prefer not to derive from what the API is returning by adding a returned field, I implemented a filter that computes the status of a load balancer.
I implemented this filter in #550, let me know if this solves your problem.
You should be able to wait for the load balance to be healthy, using:
- name: Wait load balancer to become healthy
hetzner.hcloud.load_balancer_info:
name: my-load-balancer
register: result
until: result.hcloud_load_balancer_info[0] | hetzner.hcloud.load_balancer_status == "healthy"
retries: 5