#- name: Check ob /ping erreichbar ist
#  uri:
#    url: "http://localhost/ping"
#    status_code: 200
#    return_content: yes
#  register: ping_response
#
#- debug:
#    var: ping_response.content

- name: Healthcheck nach dem Deployment
  hosts: localhost
  connection: local
  gather_facts: false
  become: false

  vars:
    healthcheck_url: "http://127.0.0.1:8080/ping"
    max_retries: 10
    delay_between_retries: 3

  tasks:
    - name: Warte, bis der Webserver erreichbar ist
      uri:
        url: "{{ healthcheck_url }}"
        status_code: 200
        return_content: yes
      register: healthcheck_response
      retries: "{{ max_retries }}"
      delay: "{{ delay_between_retries }}"
      until: >
        healthcheck_response is defined and
        healthcheck_response.status is defined and
        healthcheck_response.status == 200
      failed_when: healthcheck_response.status != 200
      ignore_errors: false

    - name: Ausgabe des Healthcheck-Resultats
      debug:
        msg: "Healthcheck erfolgreich: {{ healthcheck_response.content }}"
