main.yml (1105B)
1 --- 2 - name: Ensure /root/bin/ directory exists 3 file: 4 path: "/root/bin/" 5 state: directory 6 owner: root 7 group: root 8 mode: "0700" 9 10 - name: Place shell script to do backups 11 ansible.builtin.template: 12 src: templates/root/bin/borg-backup.sh 13 dest: /root/bin/borg-backup.sh 14 owner: root 15 group: root 16 mode: "0700" 17 18 - name: Check SSH key for backups exists 19 stat: 20 path: "/root/.ssh/borg" 21 register: have_ssh_key 22 23 - name: Place ssh configuration 24 ansible.builtin.template: 25 src: templates/root/.ssh/config 26 dest: /root/.ssh/config 27 owner: root 28 group: root 29 mode: "0600" 30 31 - name: Add host key for borg server 32 ansible.builtin.shell: 33 cmd: ssh-keyscan {{ BORG_HOST }} >> .ssh/known_hosts 34 creates: /root/.ssh/known_hosts 35 36 - name: Fail if we do not have an SSH key for the backup server 37 fail: 38 msg: "You need to first run extract-borg-key.sh" 39 when: not have_ssh_key.stat.exists 40 41 - name: Create cron job to run daily backups 42 ansible.builtin.cron: 43 name: "perform backup" 44 minute: "43" 45 hour: "2" 46 job: "/root/bin/borg-backup.sh"