Support Debian

This commit is contained in:
2024-07-13 14:33:47 +01:00
parent 713e7541bc
commit 7f5275d240
8 changed files with 58 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
--- ---
borgmatic_ssh_keys: [] borgmatic_ssh_keys: []
borgmatic_config: borgmatic_config:
# Where to look for files to backup, and where to store those backups. # Where to look for files to backup, and where to store those backups.
# See https://borgbackup.readthedocs.io/en/stable/quickstart.html and # See https://borgbackup.readthedocs.io/en/stable/quickstart.html and

View File

@@ -3,7 +3,7 @@ allow_duplicates: false
galaxy_info: galaxy_info:
role_name: borgmatic role_name: borgmatic
author: Andrew Williams author: nikdoof
description: Installs and configures a Borgmatic description: Installs and configures a Borgmatic
license: MIT license: MIT
@@ -13,3 +13,6 @@ galaxy_info:
- name: EL - name: EL
versions: versions:
- 8 - 8
- name: Debian
versions:
- bookworm

View File

@@ -6,13 +6,15 @@
owner: root owner: root
group: root group: root
mode: "0700" mode: "0700"
- name: Write borgmatic config - name: Write borgmatic config
copy: copy:
dest: /etc/borgmatic/config.yaml dest: /etc/borgmatic/config.yaml
owner: root owner: root
group: root group: root
mode: "0600" mode: "0600"
content: "{{ borgmatic_config | to_nice_yaml( width=50, explicit_start=True, explicit_end=True) }}" content: "{{ borgmatic_config | to_nice_yaml(width=50, explicit_start=True, explicit_end=True) }}"
- name: Create /root/.borgmatic folder - name: Create /root/.borgmatic folder
ansible.builtin.file: ansible.builtin.file:
path: /root/.borgmatic path: /root/.borgmatic
@@ -20,6 +22,7 @@
owner: root owner: root
group: root group: root
mode: "0700" mode: "0700"
- name: "Copy SSH key {{ item }} to borgmatic config folder" - name: "Copy SSH key {{ item }} to borgmatic config folder"
ansible.builtin.copy: ansible.builtin.copy:
src: "ssh_keys/{{ item }}" src: "ssh_keys/{{ item }}"

View File

@@ -1,9 +1,26 @@
--- ---
- name: Get borg target host SSH host key
ansible.builtin.command: "ssh-keyscan -H {{ item.split('@')[1].split(':')[0] }}"
loop: "{{ borgmatic_config['location']['repositories'] }}"
when:
- "'location' in borgmatic_config"
- "'repositories' in borgmatic_config['location']"
register: _borgmatic_ssh_host_keys
- name: Add SSH key to known hosts
ansible.builtin.known_hosts:
path: /etc/ssh/ssh_known_hosts
name: "{{ item.item.split('@')[1].split(':')[0] }}"
key: "{{ item.stdout }}"
loop: "{{ _borgmatic_ssh_host_keys.results }}"
loop_control:
label: "{{ item.item }}"
- name: Initialize borg check_repositories - name: Initialize borg check_repositories
ansible.builtin.command: "/usr/local/bin/borgmatic init --encryption repokey" # noqa 301 ansible.builtin.shell: "borgmatic init --encryption repokey"
no_log: true environment:
async: 300 PATH: "{{ ansible_env.PATH}}:/usr/local/bin"
poll: 0
- name: Enable borgmatic.timer - name: Enable borgmatic.timer
ansible.builtin.systemd: ansible.builtin.systemd:
name: borgmatic.timer name: borgmatic.timer

View File

@@ -1,17 +1,21 @@
--- ---
- name: Install BorgBackup - name: Install BorgBackup
ansible.builtin.package: ansible.builtin.package:
name: "{{ packages }}" name: borgbackup
state: installed state: present
vars:
packages: - name: Install Borgmatic (Pip)
- borgbackup
- name: Install Borgmatic
ansible.builtin.pip: ansible.builtin.pip:
name: "{{ packages }}" name: borgmatic
vars: when:
packages: - borgmatic_install_from_pip | default(false)
- borgmatic
- name: Install Borgmatic (Package)
ansible.builtin.package:
name: borgmatic
when:
- borgmatic_install_from_package | default(false)
- name: Add borgmatic systemd units - name: Add borgmatic systemd units
ansible.builtin.copy: ansible.builtin.copy:
src: "systemd/{{ item }}" src: "systemd/{{ item }}"
@@ -23,3 +27,5 @@
loop: loop:
- borgmatic.service - borgmatic.service
- borgmatic.timer - borgmatic.timer
when:
- borgmatic_install_from_pip | default(false)

View File

@@ -1,4 +1,9 @@
--- ---
- include: install.yaml - name: Borgmatic - Get OS specific vars
- include: config.yaml include_vars: "{{ item }}"
- include: init.yaml with_first_found:
- "os/{{ ansible_os_family }}/{{ ansible_distribution_major_version }}.yaml"
- "os/{{ ansible_os_family }}.yaml"
- include_tasks: install.yaml
- include_tasks: config.yaml
- include_tasks: init.yaml

2
vars/os/Debian.yaml Normal file
View File

@@ -0,0 +1,2 @@
---
borgmatic_install_from_package: true

2
vars/os/RedHat.yaml Normal file
View File

@@ -0,0 +1,2 @@
---
borgmatic_install_from_pip: true