ansible-collections / hetzner.hcloud

A collection to manage resources on Hetzner Cloud
https://galaxy.ansible.com/ui/repo/published/hetzner/hcloud
GNU General Public License v3.0
100 stars 35 forks source link

hcloud_load_balancer_info don't return status #467

Open EHEX-schildt opened 4 months ago

EHEX-schildt commented 4 months ago
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
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
                }
            ]
        }
    ]
}
jooola commented 4 months ago

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:

See https://docs.hetzner.cloud/#load-balancers-get-a-load-balancer

jooola commented 4 months ago

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

EHEX-schildt commented 4 months ago

Thanks a i realized this a few minutes before and delete my comment ;-)

EHEX-schildt commented 4 months ago

Ok so there is no way to verify the overall Health of a loadbalencer with label_selector targets?

jooola commented 4 months ago

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
        }
      ]
    }
  ]
}
github-actions[bot] commented 1 month ago

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.

EHEX-schildt commented 1 month ago

not stale