Add support for custom configuration for borgmatic (#195)

* Add support for custom configuration for borgmatic
* Restrict borgmatic_custom_config to version 1.8+
This commit is contained in:
Emiel Molenaar 2026-01-06 15:43:47 +01:00 committed by GitHub
parent 51e099e553
commit 4cb112712b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 37 additions and 0 deletions

View File

@ -60,7 +60,26 @@ Works great with [BorgBase.com](https://www.borgbase.com) - Simple and Secure Ho
keep_monthly: 6
```
## Example playbook with custom configuration options (borgmatic 1.8+)
**Note:** `borgmatic_custom_config` requires borgmatic 1.8.0 or later.
```
- hosts: all
roles:
- role: borgbase.ansible_role_borgbackup
borg_encryption_passphrase: CHANGEME
borg_repository: ssh://xxxxxx@xxxxxx.repo.borgbase.com/./repo
borg_source_directories:
- /var/www
borgmatic_custom_config:
uptime_kuma:
push_url: https://uptime.kuma.example.com/abcd1234
ntfy:
topic: backups
server: https://ntfy.sh
output_verbosity: 1
```
## Installation
@ -121,6 +140,7 @@ $ git clone https://github.com/borgbase/ansible-role-borgbackup.git roles/ansibl
- `borgmatic_store_atime`: Store atime into archive. Defaults to `true`
- `borgmatic_store_ctime`: Store ctime into archive. Defaults to `true`
- `borgmatic_version`: Force a specific borgmatic version to be installed
- `borgmatic_custom_config`: Custom YAML configuration (as a dictionary) to add to the borgmatic config file. Allows adding any additional borgmatic options not covered by other variables. **Requires borgmatic 1.8.0 or later.** See example above.
- `borg_user`: Name of the User to create Backups (service account)
- `borg_group`: Name of the Group to create Backups (service account)

View File

@ -46,6 +46,7 @@ borgmatic_store_ctime: true
borgmatic_relocated_repo_access_is_ok: false
borgmatic_unknown_unencrypted_repo_access_is_ok: false
borgmatic_version: ">=1.7.11"
borgmatic_custom_config: {}
borg_venv_path: "/opt/borgmatic"
borg_user: "root"

View File

@ -211,6 +211,10 @@ argument_specs:
type: str
required: false
description: Borgmatic version to install. Defaults to 'latest'
borgmatic_custom_config:
type: dict
required: false
description: Custom YAML configuration to add to the borgmatic config file. Allows adding any additional borgmatic options not covered by other variables. Requires borgmatic 1.8.0 or later.
borg_ssh_key_type:
type: str
required: false

View File

@ -12,6 +12,12 @@
ansible.builtin.set_fact:
borgmatic_version: "{{ borgmatic_version_output.stdout.split()[0] }}"
- name: Ensure custom config is only used with borgmatic 1.8+
ansible.builtin.assert:
that:
- borgmatic_custom_config is not defined or borgmatic_custom_config | length == 0 or borgmatic_version is version('1.8.0', '>=')
msg: "borgmatic_custom_config requires borgmatic 1.8.0 or later. Detected version: {{ borgmatic_version }}"
- name: Ensure /etc/borgmatic exists
ansible.builtin.file:
path: /etc/borgmatic

View File

@ -197,3 +197,9 @@ check_last: {{ borgmatic_check_last }}
{{ hook }}:
{{ borgmatic_hooks[hook] | to_nice_yaml(indent=4) | indent(4, first=true) }}
{% endfor %}
{% if borgmatic_custom_config is defined and borgmatic_custom_config %}
# Custom configuration
{{ borgmatic_custom_config | to_nice_yaml(indent=4) }}
{% endif %}