---
# Playbook 99: Emergency Rollback
# Stop and remove the deployment (keeps backups)

- name: Emergency Rollback
  hosts: all
  become: yes
  
  tasks:
    - name: Confirm rollback
      pause:
        prompt: |
          ⚠️  WARNING: This will stop and remove all containers!
          Backups in {{ deployment_dir }}/backups/ will be preserved.
          Press ENTER to continue or Ctrl+C to cancel

    - name: Stop Docker Compose stack
      command: docker compose down
      args:
        chdir: "{{ deployment_dir }}"
      become_user: "{{ ansible_user }}"
      ignore_errors: yes

    - name: Remove deployment directory (except backups)
      shell: |
        cd {{ deployment_dir }}
        rm -rf configs data docker-compose.yml .env
        ls -la
      args:
        warn: false

    - name: Display rollback status
      debug:
        msg: |
          ✓ Containers stopped and removed
          ✓ Deployment files removed
          ✓ Backups preserved in {{ deployment_dir }}/backups/
          ✓ Docker volumes preserved (use 'docker volume ls' to see)
          
          To completely remove volumes (DELETES ALL DATA):
          cd {{ deployment_dir }} && docker compose down -v
