--- - name: Install sqlite3 for consistent copies of live databases ansible.builtin.apt: name: [sqlite3, bzip2] state: present - name: Check the installed restic version ansible.builtin.command: /usr/local/bin/restic version register: restic_installed changed_when: false failed_when: false check_mode: false - name: Install restic {{ restic_version }} when: ("restic " ~ restic_version ~ " ") not in (restic_installed.stdout | default('')) block: - name: Download the release ansible.builtin.get_url: url: "https://github.com/restic/restic/releases/download/v{{ restic_version }}/restic_{{ restic_version }}_linux_amd64.bz2" dest: "/tmp/restic_{{ restic_version }}.bz2" checksum: "sha256:https://github.com/restic/restic/releases/download/v{{ restic_version }}/SHA256SUMS" mode: "0600" - name: Unpack it ansible.builtin.shell: > bunzip2 -c /tmp/restic_{{ restic_version }}.bz2 > /usr/local/bin/restic.new && chmod 755 /usr/local/bin/restic.new && mv /usr/local/bin/restic.new /usr/local/bin/restic && rm /tmp/restic_{{ restic_version }}.bz2 changed_when: true - name: Create config and cache directories ansible.builtin.file: path: "{{ item }}" state: directory mode: "0700" loop: [/etc/restic, /var/cache/restic] - name: Write credentials ansible.builtin.template: src: env.j2 dest: /etc/restic/env mode: "0600" diff: false - name: Install the scripts ansible.builtin.template: src: restic-backup.j2 dest: /usr/local/sbin/restic-backup mode: "0700" - name: Install the alert script ansible.builtin.copy: src: restic-alert dest: /usr/local/sbin/restic-alert mode: "0700" - name: Install the systemd units ansible.builtin.template: src: "{{ item }}.j2" dest: "/etc/systemd/system/{{ item }}" mode: "0644" loop: [restic-backup.service, restic-backup.timer] notify: Reload systemd - name: Install the alert unit ansible.builtin.copy: src: restic-alert@.service dest: /etc/systemd/system/restic-alert@.service mode: "0644" notify: Reload systemd - name: Flush handlers ansible.builtin.meta: flush_handlers - name: Create the repositories ansible.builtin.command: /usr/local/sbin/restic-backup init register: restic_init changed_when: "'created' in restic_init.stdout" when: not ansible_check_mode - name: Enable the nightly timer ansible.builtin.systemd: name: restic-backup.timer enabled: true state: started # On a first dry run the unit is not installed yet ignore_errors: "{{ ansible_check_mode }}"