Files
jeet d2e8cc6e70 Fix issues 3,5,6,7,8,9,11,15,16: security hardening and reliability improvements
- ansible.cfg: enable host_key_checking (closes #1)
- update_upgrade.yml: fix reboot crash on non-Debian hosts, exclude AnsibleHost from targets (closes #2, #7)
- deploy.yml: replace silent ignore_errors with real container health assertion (closes #3)
- redeploy.yml: same assertion fix + restic --overwrite always + RESTIC_RESTORE_PATH variable (closes #3, #4, #5)
- disaster.yml: same fixes as redeploy.yml (closes #3, #4, #5)
- docker_update_containers.yml: create missing playbook (closes #6)
- fresh_install.yml: add safety guard to abort if containers already running (closes #8)
- docker_status.yml: add become: true (closes #9)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 14:14:14 -04:00

30 lines
1.0 KiB
YAML

---
- name: Check and Report Status of Docker Containers
hosts: Docker
gather_facts: true
become: true
vars:
exited_containers: []
tasks:
- name: Check container status
ansible.builtin.shell: |
docker ps -a --format "{{ '{{' }}.Names{{ '}}' }}\t{{ '{{' }}.Status{{ '}}' }}\t{{ '{{' }}.Ports{{ '}}' }}"
register: container_status
- name: Collect exited containers
set_fact:
exited_containers: "{{ exited_containers + [item.split('\t')[0]] }}"
loop: "{{ container_status.stdout_lines }}"
when: "'Exited' in item.split('\t')[1]"
- name: Display container status for each host
ansible.builtin.debug:
msg: "Container: {{ item.split('\t')[0] }}, Status: {{ item.split('\t')[1] }}, Ports: {{ item.split('\t')[2] or 'None' }}"
loop: "{{ container_status.stdout_lines }}"
- name: Fail with summary of exited containers
ansible.builtin.fail:
msg: "Exited containers found: {{ exited_containers | join(', ') }}"
when: exited_containers | length > 0