---
# Trigger backups across all instances
# Usage: ansible-playbook playbooks/backup.yml [--limit hostname]

- name: Run Changemaker Lite backups
  hosts: changemaker_instances
  become: true

  tasks:
    - name: Run backup script
      ansible.builtin.command:
        cmd: ./scripts/backup.sh --retention {{ cml_backup_retention_days }}
        chdir: "{{ cml_deploy_path }}"
      register: backup_result
      changed_when: "'Backup complete' in backup_result.stdout"

    - name: Show backup result
      ansible.builtin.debug:
        msg: "{{ backup_result.stdout_lines | last }}"
