add borgmatic role

This commit is contained in:
Sergey Malyuk
2025-12-12 17:22:02 +03:00
parent c715157a7c
commit e16cc72ab2
23 changed files with 432 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
---
- name: Converge
hosts: all
vars:
repo_path: "/home/borg/test-repo"
pre_tasks:
- name: "Create a user for borg"
ansible.builtin.user:
name: borg
shell: /bin/bash
create_home: true
- name: "Generate test data file"
ansible.builtin.copy:
dest: "/tmp/data"
content: "This is a test file!"
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}"
mode: "0644"
- name: "Ensure the repo path exists"
ansible.builtin.file:
path: "{{ repo_path }}"
state: directory
owner: "borg"
mode: "0700"
- name: "Install openssh-server"
ansible.builtin.apt:
name: openssh-server
state: present
update_cache: true
- name: "Start an SSH openssh-server"
ansible.builtin.systemd:
name: ssh
state: started
roles:
- role: genlab.borgmatic
borg_source_directories:
- "/tmp/data"
borg_repo_path: "ssh://borg@localhost/./test-repo"
borg_repo_label: "test-repo"
borg_encryption_passphrase: "secret"
repo_server_inventory_hostname: ubuntu # in production this should be an Ansible inventory hostname
repo_server_user: borg

View File

@@ -0,0 +1,31 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
provisioner:
name: ansible
verifier:
name: ansible
scenario:
name: default
test_sequence:
- destroy
- create
- converge
# - idempotence
- verify

View File

@@ -0,0 +1,48 @@
---
- name: Verify
hosts: all
gather_facts: false
any_errors_fatal: true
vars:
repo_path: "/home/borg/test-repo"
tasks:
- name: "Include default vars"
ansible.builtin.include_vars:
dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/"
extensions: [ 'yml' ]
- name: "Check if Borg is installed"
changed_when: false
register: borg_installed_version
ansible.builtin.command: "/usr/bin/borg --version"
- name: "Check Borg version"
ansible.builtin.assert:
that: borg_installed_version.stdout.find(borg_version)
success_msg: "borg version {{ borg_version }} is installed and working"
fail_msg: "borg version {{ borg_version }} is not installed or not working correctly"
- name: "Check if Borgmatic is installed"
changed_when: false
register: borgmatic_installed_version
ansible.builtin.command:
cmd: "/usr/bin/borgmatic --version"
- name: "Check that the test repo was created"
register: test_repo_readme
failed_when: test_repo_readme.stat.exists is false
ansible.builtin.stat:
path: "{{ repo_path }}"
- name: "Check that the systemd timer for Borgmatic is up and running"
register: timer
ansible.builtin.systemd:
name: borgmatic.timer
- name: "Assert that the timer is running"
ansible.builtin.assert:
that: timer.status.ActiveState == "active"
success_msg: "Timer is running"
fail_msg: "Unexpected timer state: '{{ timer.status.ActiveState }}'"