--- - name: Run backups hosts: docker_hosts become: true tasks: - name: Ensure backup destination exists ansible.builtin.file: path: "{{ backup_destination }}" state: directory mode: "0750" tags: [backup] - name: Run backup script ansible.builtin.command: cmd: /usr/local/bin/homelab-backup.sh register: backup_result changed_when: backup_result.rc == 0 tags: [backup] - name: Display backup result ansible.builtin.debug: msg: "{{ backup_result.stdout_lines }}" tags: [backup] - name: Clean up backups older than 30 days ansible.builtin.find: paths: "{{ backup_destination }}" age: 30d recurse: false file_type: file patterns: "*.tar.gz" register: old_backups tags: [backup, cleanup] - name: Remove old backups ansible.builtin.file: path: "{{ item.path }}" state: absent loop: "{{ old_backups.files }}" loop_control: label: "{{ item.path | basename }}" tags: [backup, cleanup]