Ansible_workstation/roles/borgmatic/tasks/main.yml

68 lines
1.5 KiB
YAML
Raw Normal View History

2022-03-04 14:24:09 +00:00
---
# tasks file for borgmatic
2022-03-09 09:46:21 +00:00
- name: debug
debug:
msg: "{{ borgmatic_config_file }}"
- name: Assert borg_source_directories not empty
assert:
that: "{{ borg_source_directories != [] }}"
- name: Assert borg_repository not empty
assert:
that: "{{ borg_repository != [] }}"
2022-03-08 13:42:14 +00:00
- name: stat on sources
stat:
path: "{{ item }}"
with_items: "{{ borg_source_directories }}"
register: sources_exists
- name: Assert sources exists
assert:
that: "{{ item }}.stat.exists"
with_items: "{{ sources_exists.results }}"
2022-03-04 14:24:09 +00:00
- name: Install borg and borgmatic
apt:
name: "{{ item }}"
state: present
with_items:
2022-03-08 13:42:14 +00:00
- borgbackup
2022-03-04 14:24:09 +00:00
- borgmatic
2022-03-08 13:42:14 +00:00
- name: Make dir for borgmatic in etc
file:
path: "/etc/borgmatic"
state: directory
- name: Borgmatic config
template:
src: config.yaml.j2
2022-03-09 09:46:21 +00:00
dest: "{{ borgmatic_config_file }}"
2022-03-08 13:42:14 +00:00
mode: 644
validate: "validate-borgmatic-config -c %s"
2022-03-08 13:42:14 +00:00
- name: copy systemd service
template:
src: service.j2
2022-03-09 09:46:21 +00:00
dest: "/lib/systemd/system/borgmatic_{{ borgmatic_name }}.service"
2022-03-08 13:42:14 +00:00
mode: 644
notify: "reload systemd"
2022-03-08 13:42:14 +00:00
2022-03-09 09:46:21 +00:00
- name: copy systemd timer for executing borgmatic after boot
template:
src: afterboot.timer.j2
2022-03-09 09:46:21 +00:00
dest: "/lib/systemd/system/borgmatic_{{ borgmatic_name }}.timer"
2022-03-08 13:42:14 +00:00
notify: "reload systemd"
- name: disable service
systemd:
name: "borgmatic_{{ borgmatic_name }}.service"
enabled: no
2022-03-08 13:42:14 +00:00
- name: enable timer
systemd:
name: "borgmatic_{{ borgmatic_name }}.timer"
2022-03-08 13:42:14 +00:00
enabled: yes