---
# docker-compose-service role — 確保 Docker Compose 服務運作中
# 呼叫方式: include_role: name=docker-compose-service
#   vars:
#     service_name: n8n
#     service_dir: /opt/n8n

- name: "{{ service_name }} | 確認容器運作中"
  ansible.builtin.command:
    cmd: "docker ps --filter name={{ service_name }} --filter status=running --format '{{ '{{' }}.Names{{ '}}' }}'"
  register: _svc_status
  changed_when: false

- name: "{{ service_name }} | 若停止則啟動"
  ansible.builtin.command:
    cmd: "docker compose up -d"
    chdir: "{{ service_dir }}"
  when: _svc_status.stdout == ""
