---
# Restart a specific service
# Usage: ansible-playbook playbooks/common/restart_service.yml -e "service_name=plex" -e "target_host=atlantis"
- name: Restart Docker service
  hosts: "{{ target_host }}"
  gather_facts: false

  tasks:
    - name: Validate service_name is provided
      ansible.builtin.fail:
        msg: "service_name variable is required. Use -e 'service_name=<name>'"
      when: service_name is not defined

    - name: Restart service
      ansible.builtin.command:
        cmd: docker compose restart
        chdir: "{{ docker_data_path }}/{{ service_name }}"
      register: restart_result
      become: "{{ ansible_become | default(false) }}"

    - name: Display result
      ansible.builtin.debug:
        msg: "Service {{ service_name }} restarted on {{ inventory_hostname }}"
