---
# AWOOOI Ansible - 192.168.0.188 read-only check-mode evidence.
# This playbook intentionally avoids become/sudo and performs no mutations.

- name: "192.168.0.188 AI+Web read-only evidence"
  hosts: host_188
  gather_facts: false
  become: false

  vars:
    expected_188_containers:
      - openclaw
      - tsenyang-website
      - momo-pro-system
      - momo-db
      - signoz
      - minio
      - n8n
      - open-webui
      - docker-registry

  tasks:
    - name: "Preflight | collect remote user"
      ansible.builtin.command:
        cmd: "id -un"
      register: remote_identity
      changed_when: false
      check_mode: false

    - name: "Docker | collect running container names"
      ansible.builtin.command:
        cmd: "docker ps --format '{{ '{{' }}.Names{{ '}}' }}'"
      register: running_containers
      changed_when: false
      check_mode: false

    - name: "Docker | collect restarting containers"
      ansible.builtin.command:
        cmd: "docker ps --filter status=restarting --format '{{ '{{' }}.Names{{ '}}' }}'"
      register: restarting_containers
      changed_when: false
      check_mode: false

    - name: "Docker | calculate missing expected containers"
      ansible.builtin.set_fact:
        missing_expected_containers: >-
          {{ expected_188_containers | difference(running_containers.stdout_lines | default([])) }}
      changed_when: false

    - name: "Backup | inspect momo PostgreSQL backup script"
      ansible.builtin.stat:
        path: /home/ollama/momo-pro/scripts/pg_backup.sh
      register: momo_pg_backup_script

    - name: "Backup | inspect AwoooP ops notification helper"
      ansible.builtin.stat:
        path: /home/ollama/momo-pro/scripts/notify-awoooi-ops.sh
      register: momo_notify_helper

    - name: "Backup | inspect momo backup directory"
      ansible.builtin.stat:
        path: /home/ollama/momo_backups
      register: momo_backup_dir

    - name: "Backup | collect ollama crontab"
      ansible.builtin.command:
        cmd: "crontab -l"
      register: ollama_crontab
      changed_when: false
      failed_when: ollama_crontab.rc not in [0, 1]
      check_mode: false

    - name: "Evidence | emit read-only summary"
      ansible.builtin.debug:
        msg:
          - "remote_user={{ remote_identity.stdout | default('unknown') }}"
          - "running_containers={{ running_containers.stdout_lines | default([]) | join(',') }}"
          - "restarting_containers={{ restarting_containers.stdout_lines | default([]) | join(',') }}"
          - "missing_expected_containers={{ missing_expected_containers | default([]) | join(',') }}"
          - "pg_backup_exists={{ momo_pg_backup_script.stat.exists | default(false) }}"
          - "pg_backup_executable={{ momo_pg_backup_script.stat.executable | default(false) }}"
          - "notify_helper_exists={{ momo_notify_helper.stat.exists | default(false) }}"
          - "notify_helper_executable={{ momo_notify_helper.stat.executable | default(false) }}"
          - "backup_dir_exists={{ momo_backup_dir.stat.exists | default(false) }}"
          - "cron_has_pg_backup={{ '/home/ollama/momo-pro/scripts/pg_backup.sh' in (ollama_crontab.stdout | default('')) }}"
