ansible/roles/borgbackup-client/tasks/main.yml

88 lines
2.0 KiB
YAML

---
- name: Pin borgmatic
template:
src: apt/{{ item }}.j2
dest: /etc/apt/{{ item }}
loop:
- sources.list.d/bullseye.list
- preferences.d/borgmatic-bullseye
when:
- ansible_distribution == "Debian"
- ansible_distribution_major_version | int <= 10
- ansible_distribution_release != "bullseye"
- name: Don't pin borgmatic if we are on bullseye
file:
path: /etc/apt/{{ item }}
state: absent
loop:
- sources.list.d/bullseye.list
- preferences.d/borgmatic-bullseye
when:
- ansible_distribution == "Debian"
- ansible_distribution_release == "bullseye"
- name: Install borgbackup
apt:
update_cache: true
name:
- borgbackup
- borgmatic
state: present
register: apt_result
retries: 3
until: apt_result is succeeded
- name: Ensures /etc/borgmatic exists
file:
path: /etc/borgmatic
state: directory
mode: 0700
owner: root
- name: Deploy ssh private key
template:
src: borgmatic/id_ed25519_borg.j2
dest: /etc/borgmatic/id_ed25519_borg
mode: 0600
owner: root
- name: Deploy borgmatic config
template:
src: borgmatic/config.yaml.j2
dest: /etc/borgmatic/config{{ borg.path_suffix | default('') }}.yaml
mode: 0600
owner: root
group: root
- name: Init borg repository
command:
cmd: /usr/bin/borgmatic init -c /etc/borgmatic/config{{ borg.path_suffix | default('') }}.yaml -e repokey
register: borg_init
changed_when: '"does not exist" in borg_init.stderr'
- name: Deploy borgmatic systemd
template:
src: "systemd/system/{{ item }}.j2"
dest: /etc/systemd/system/{{ item }}
mode: 0600
owner: root
group: root
loop:
- borgmatic.service
- borgmatic.timer
notify:
- Restart timer
- systemctl daemon-reload
- name: Indicate role in motd
template:
src: update-motd.d/04-service.j2
dest: /etc/update-motd.d/04-borgbackup
mode: 0755
- name: Enable timer
service:
name: borgmatic.timer
enabled: true