2021-03-11 23:29:57 +01:00
|
|
|
---
|
|
|
|
- name: Pin borgmatic
|
|
|
|
template:
|
2021-03-14 14:17:36 +01:00
|
|
|
src: "{{ item.src }}"
|
|
|
|
dest: "{{ item.dest }}"
|
2021-03-11 23:36:27 +01:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: u=rw,g=r,o=
|
2021-03-11 23:29:57 +01:00
|
|
|
loop:
|
2021-03-14 14:17:36 +01:00
|
|
|
- src: apt/list.j2
|
|
|
|
dest: /etc/apt/sources.list.d/bullseye.list
|
|
|
|
- src: apt/preferences.j2
|
|
|
|
dest: /etc/apt/preferences.d/borgmatic-bullseye
|
2021-03-11 23:29:57 +01:00
|
|
|
when:
|
2021-03-16 13:47:14 +01:00
|
|
|
- "ansible_distribution == 'Debian'"
|
2021-05-23 14:02:20 +02:00
|
|
|
- "ansible_distribution_major_version in ('stretch', 'buster', '9', '10')"
|
2021-03-11 23:29:57 +01:00
|
|
|
|
|
|
|
- name: Install borgmatic
|
|
|
|
apt:
|
|
|
|
name: borgmatic
|
2021-03-14 19:03:44 +01:00
|
|
|
update_cache: true
|
2021-03-11 23:29:57 +01:00
|
|
|
register: apt_result
|
|
|
|
retries: 3
|
|
|
|
until: apt_result is succeeded
|
|
|
|
|
2021-03-15 01:04:42 +01:00
|
|
|
- name: Create configuration directory for borgmatic
|
2021-03-14 14:17:36 +01:00
|
|
|
file:
|
2021-03-14 18:42:26 +01:00
|
|
|
path: /etc/borgmatic
|
2021-03-14 14:17:36 +01:00
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: root
|
2021-03-15 01:04:42 +01:00
|
|
|
mode: u=rwx,g=rx,o=
|
2021-03-14 18:42:26 +01:00
|
|
|
|
|
|
|
- name: Add borgmatic configuration file
|
|
|
|
become: true
|
|
|
|
template:
|
|
|
|
src: config.yaml.j2
|
|
|
|
dest: /etc/borgmatic/config.yaml
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: u=rw,g=r,o=
|
|
|
|
vars:
|
2021-03-15 07:25:09 +01:00
|
|
|
borg_host_dir: "/borg/{{ inventory_hostname }}"
|
2021-03-14 14:17:36 +01:00
|
|
|
|
2021-03-11 23:29:57 +01:00
|
|
|
- name: Create SSH key
|
|
|
|
openssh_keypair:
|
2021-03-14 18:42:26 +01:00
|
|
|
path: "/etc/borgmatic/id_remote"
|
2021-03-14 16:11:18 +01:00
|
|
|
type: ed25519
|
|
|
|
regenerate: full_idempotence
|
2021-03-11 23:29:57 +01:00
|
|
|
owner: root
|
|
|
|
group: root
|
2021-03-14 18:22:52 +01:00
|
|
|
mode: u=rw,g=,o=
|
2021-03-11 23:29:57 +01:00
|
|
|
register: ssh_key
|
2021-03-15 01:04:42 +01:00
|
|
|
|
|
|
|
- name: Gather SSH host keys
|
2021-03-14 16:11:18 +01:00
|
|
|
delegate_to: "{{ borg_server_host }}"
|
2021-03-15 01:04:42 +01:00
|
|
|
command: "ssh-keyscan {{ borg_server_host }}"
|
|
|
|
register: keys
|
|
|
|
|
2021-03-14 16:11:18 +01:00
|
|
|
- name: Add server key to known hosts
|
|
|
|
known_hosts:
|
|
|
|
hash_host: true
|
|
|
|
host: "{{ borg_server_host }}"
|
2021-03-15 01:04:42 +01:00
|
|
|
key: "{{ item }}"
|
|
|
|
loop: "{{ keys.stdout_lines }}"
|
2021-03-11 23:29:57 +01:00
|
|
|
|
|
|
|
- name: Add public key to remote
|
|
|
|
delegate_to: "{{ borg_server_host }}"
|
2021-03-14 13:18:30 +01:00
|
|
|
become: true
|
2021-03-11 23:29:57 +01:00
|
|
|
authorized_key:
|
|
|
|
exclusive: false
|
2021-03-14 13:18:30 +01:00
|
|
|
user: "{{ borg_server_user }}"
|
2021-03-11 23:29:57 +01:00
|
|
|
key: "{{ ssh_key.public_key }}"
|
2021-03-14 18:42:26 +01:00
|
|
|
key_options: "{{ options | join(',') }}"
|
2021-03-14 18:22:52 +01:00
|
|
|
vars:
|
2021-03-15 07:25:09 +01:00
|
|
|
borg_host_dir: "/borg/{{ inventory_hostname }}"
|
2021-03-14 18:42:26 +01:00
|
|
|
options:
|
|
|
|
- 'command="borg serve --restrict-to-path {{ borg_host_dir }}"'
|
|
|
|
- no-agent-forwarding
|
|
|
|
- no-port-forwarding
|
|
|
|
- no-pty
|
|
|
|
- no-user-rc
|
|
|
|
- no-X11-forwarding
|
2021-03-14 18:22:52 +01:00
|
|
|
|
|
|
|
- name: Init repository
|
|
|
|
command: borgmatic init --encryption repokey
|
2021-03-11 23:29:57 +01:00
|
|
|
|
|
|
|
- name: Install timer and service for borgmatic
|
|
|
|
template:
|
|
|
|
src: "{{ item }}.j2"
|
|
|
|
dest: "/etc/systemd/system/{{ item }}"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: u=rw,g=r,o=
|
|
|
|
loop:
|
|
|
|
- borgmatic.timer
|
|
|
|
- borgmatic.service
|
|
|
|
notify:
|
|
|
|
- Run systemd daemon-reload
|
|
|
|
|
2021-03-14 18:22:52 +01:00
|
|
|
- name: Run systemd deamon-reload
|
|
|
|
systemd:
|
|
|
|
daemon_reload: true
|
|
|
|
|
2021-03-14 13:16:08 +01:00
|
|
|
- name: Start and enable borgmatic timer
|
|
|
|
systemd:
|
|
|
|
name: borgmatic.timer
|
|
|
|
state: started
|
|
|
|
enabled: true
|
2021-03-11 23:29:57 +01:00
|
|
|
...
|