Ansible_workstation/roles/borgmatic/tasks/main.yml

63 lines
1.4 KiB
YAML

---
# tasks file for borgmatic
- name: debug
debug:
msg: "{{ borgmatic_config_file }}"
- 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 }}"
- name: Install borg and borgmatic
apt:
name: "{{ item }}"
state: present
with_items:
- borgbackup
- borgmatic
- name: Make dir for borgmatic in etc
file:
path: "/etc/borgmatic"
state: directory
- name: Borgmatic config
template:
src: borgmatic.config.yaml.j2
dest: "{{ borgmatic_config_file }}"
mode: 644
- name: Check borgmatic config
command:
cmd: "validate-borgmatic-config -c {{ borgmatic_config_file}}"
register: validate_borgmatic_config
- name: Assert that config is validate
assert:
that: validate_borgmatic_config.failed != true
- name: copy systemd service
template:
src: borgmatic.service.j2
dest: "/lib/systemd/system/borgmatic_{{ borgmatic_name }}.service"
mode: 644
notify: reload systemd
- name: copy systemd timer for executing borgmatic after boot
template:
src: borgmatic.afterboot.timer.j2
dest: "/lib/systemd/system/borgmatic_{{ borgmatic_name }}.timer"
notify: "reload systemd"
- name: enable timer
systemd:
name: "borgmatic_{{ borgmatic_name }}"
enabled: yes