---
# Post-deploy health checks

- name: Wait for API to respond
  ansible.builtin.uri:
    url: "http://localhost:{{ cml_api_port }}/api/health"
    method: GET
    status_code: 200
    timeout: 5
  register: api_health
  retries: 15
  delay: 3
  until: api_health.status == 200

- name: Wait for Admin GUI to respond
  ansible.builtin.uri:
    url: "http://localhost:{{ cml_admin_port }}"
    method: GET
    status_code: 200
    timeout: 5
  register: admin_health
  retries: 10
  delay: 3
  until: admin_health.status == 200

- name: Check container health
  ansible.builtin.command:
    cmd: docker compose ps --format json
    chdir: "{{ cml_deploy_path }}"
  register: compose_ps
  changed_when: false

- name: Report deployment status
  ansible.builtin.debug:
    msg: |
      Deployment health check:
        API:   {{ 'OK' if api_health.status == 200 else 'FAILED' }}
        Admin: {{ 'OK' if admin_health.status == 200 else 'FAILED' }}
