--- - name: Health check all services hosts: docker_hosts become: true tasks: - name: Check Docker daemon is running ansible.builtin.systemd: name: docker state: started check_mode: true register: docker_status tags: [health] - name: Get running containers community.docker.docker_host_info: containers: true register: docker_info tags: [health] - name: Display container count ansible.builtin.debug: msg: "{{ inventory_hostname }}: {{ docker_info.containers | length }} containers running" tags: [health] - name: Check for unhealthy containers ansible.builtin.shell: | docker ps --filter health=unhealthy --format '{{ '{{' }}.Names{{ '}}' }}' register: unhealthy changed_when: false tags: [health] - name: Report unhealthy containers ansible.builtin.debug: msg: "WARNING: Unhealthy containers on {{ inventory_hostname }}: {{ unhealthy.stdout_lines }}" when: unhealthy.stdout | length > 0 tags: [health] - name: Check disk usage ansible.builtin.shell: | df -h / /data | tail -n +2 | awk '{print $1, $5, $6}' register: disk_usage changed_when: false tags: [health] - name: Display disk usage ansible.builtin.debug: msg: "{{ disk_usage.stdout_lines }}" tags: [health] - name: Check memory usage ansible.builtin.shell: | free -h | grep Mem | awk '{print "Total:", $2, "Used:", $3, "Free:", $4}' register: mem_usage changed_when: false tags: [health] - name: Display memory usage ansible.builtin.debug: msg: "{{ mem_usage.stdout }}" tags: [health] - name: Check key services via HTTP ansible.builtin.uri: url: "https://{{ item }}.{{ domain }}" validate_certs: false status_code: [200, 301, 302, 303, 401, 403] timeout: 10 loop: - traefik - vault - grafana - jellyfin - gitea - ha register: http_checks ignore_errors: true tags: [health] when: inventory_hostname == 'peggy' - name: Report HTTP check results ansible.builtin.debug: msg: "{{ item.item }}.{{ domain }}: {{ item.status | default('FAILED') }}" loop: "{{ http_checks.results | default([]) }}" loop_control: label: "{{ item.item | default('unknown') }}" when: inventory_hostname == 'peggy' tags: [health]