/
/
/
Ansible role that can run restic backups and push it to a remote storage server.
1---
2- name: Install restic package
3 package:
4 name: "{{ backup_restic_pkg_name }}"
5 state: present
6 when: backup_install_restic | bool
7 tags: [restic, setup]
8
9- name: Create restic environment
10 ansible.builtin.set_fact:
11 restic_environment: |
12 {
13 "RESTIC_REPOSITORY": "{{ restic_repo }}",
14 "RESTIC_PASSWORD": "{{ restic_password }}"
15 }
16 run_once: true
17
18- name: Add extra environment variables to restic environment
19 ansible.builtin.set_fact:
20 restic_environment: "{{ restic_environment | combine(restic_env_extra) }}"
21 run_once: true
22 when: restic_env_extra | length > 0
23
24- name: Check if restic repo is initialized
25 ansible.builtin.command: restic cat config
26 environment: "{{ restic_environment }}"
27 register: _restic_cat
28 failed_when: false
29 changed_when: false
30 become: yes
31
32- name: Initialize restic repo if missing
33 ansible.builtin.command: restic init
34 environment: "{{ restic_environment }}"
35 when: _restic_cat.rc != 0
36 become: yes
37
38