- name: Backup
  hosts: beepi
  become: true
  vars:
    gpg_password: !vault |
              $ANSIBLE_VAULT;1.1;AES256
              34383033383462626132353163303532376137613539326662383038663537633465373863396539
              6139623961303165353230303637303530343136363165380a323534663665323836636165323237
              39653863313962353033336338376462303962323762663139663136663033306161316361303630
              6466663761643438360a653166616130633862643236633663303731356337326361636436646439
              37303633353961623766313063363734376334383163376337376639306135373064
  tasks:
    - name: Install rsync
      ansible.builtin.apt:
        name: rsync
        state: present

    - name: Create backup directory
      ansible.builtin.file:
        path: /opt/backup
        state: directory
        mode: '0700'

    - name: Copy daily
      ansible.builtin.copy:
        src: backupDaily.sh
        dest: /opt/backup/backupDaily.sh
        mode: '0700'

    - name: Copy weekly
      ansible.builtin.copy:
        src: backupWeekly.sh
        dest: /opt/backup/backupWeekly.sh
        mode: '0700'

    - name: Copy passphrase
      ansible.builtin.template:
        src: passphrase.txt.j2
        dest: /opt/backup/passphrase.txt
        mode: '0600'

    - name: Set path
      ansible.builtin.cron:
        name: PATH
        env: true
        job: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

    - name: Schedule daily backup
      ansible.builtin.cron:
        name: beepi backup daily
        user: root
        minute: '0'
        hour: '3'
        job: /opt/backup/backupDaily.sh >> /var/log/beepi-backup.log 2>&1

    - name: Schedule weekly backup
      ansible.builtin.cron:
        name: beepi backup weekly
        user: root
        minute: '0'
        hour: '5'
        weekday: '0'
        job: /opt/backup/backupWeekly.sh >> /var/log/beepi-backup.log 2>&1
