main.yml (1331B)
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: Check whether we already know the host key of the borg server 32 ansible.builtin.command: 33 cmd: ssh-keygen -F {{ borg_host }} -f /root/.ssh/known_hosts 34 register: known_host 35 changed_when: false 36 failed_when: false 37 38 - name: Add host key for borg server 39 ansible.builtin.shell: 40 cmd: ssh-keyscan {{ borg_host }} >> /root/.ssh/known_hosts 41 when: known_host.rc != 0 42 43 - name: Fail if we do not have an SSH key for the backup server 44 fail: 45 msg: "You need to first run extract-borg-key.sh" 46 when: not have_ssh_key.stat.exists 47 48 - name: Create cron job to run daily backups 49 ansible.builtin.cron: 50 name: "perform backup" 51 minute: "43" 52 hour: "2" 53 job: "/root/bin/borg-backup.sh"