borgbase / ansible-role-borgbackup

Ansible role to set up Borg and Borgmatic
MIT License
221 stars 98 forks source link

config.yaml syntax deprecated #145

Open sinux-l5d opened 7 months ago

sinux-l5d commented 7 months ago

Hello,

Using this module I run into a deprecated warning when running borgmatic:

summary:
/etc/borgmatic/config.yaml: Configuration sections (like location:, storage:, retention:, consistency:, and hooks:) are deprecated and support will be removed from a future release. To prepare for this, move your options out of sections to the global scope.
/etc/borgmatic/config.yaml: The exclude_if_present option now expects a list value. String values for this option are deprecated and support will be removed from a future release.

The fix is quite simple, but needs some adapting for the repositories list: it now expects objects with the path and label keys.

So far, I came up with this :

#jinja2: lstrip_blocks: "True", trim_blocks: "True"
---
{# List of... #}
repositories:
{% if borg_repository is iterable and (borg_repository is not string and borg_repository is not mapping) %}
  {% for repo in borg_repository %}
  {# ...mappings #}
  {% if repo is mapping and "path" in repo and "label" in repo %}
    {{ [repo] | to_nice_yaml(indent=2) | trim | indent(4) }}
  {# ...strings (legacy) #}
  {% elif repo is string %}
    - path: {{ repo }}
      label: {{ repo }}
  {% endif %}
  {% endfor %}
{# Mapping with path and label key #}
{% elif borg_repository is defined and borg_repository is mapping and "path" in borg_repository and "label" in borg_repository %}
    - path: {{ borg_repository.path }}
      label: {{ borg_repository.label }}
{# String (legacy) #}
{% elif borg_repository is defined and borg_repository is string %}
    - path: {{ borg_repository }}
      label: {{ borg_repository }}
{% endif %}

But it's not perfect, if the label is not provided, it will use the repo path.

This template is compatible with the following:

- import_role:  borgbase.ansible_role_borgbackup
  vars:
    borg_repository: "ssh://XXXXXXXX@XXXXXXXX.repo.borgbase.com/./repo"
    [...]
- import_role:  borgbase.ansible_role_borgbackup
  vars:
    borg_repository: 
        - "ssh://XXXXXXXX@XXXXXXXX.repo.borgbase.com/./repo"
    [...]
- import_role:  borgbase.ansible_role_borgbackup
  vars:
    borg_repository:
        - path: "ssh://XXXXXXXX@XXXXXXXX.repo.borgbase.com/./repo"
          label: default
    [...]
- import_role:  borgbase.ansible_role_borgbackup
  vars:
    borg_repository:
        path: "ssh://XXXXXXXX@XXXXXXXX.repo.borgbase.com/./repo"
        label: default
    [...]

And will render into something like:

repositories:
    - path: path_here
      label: label_or_path_here

Full commit : https://github.com/sinux-l5d/ansible-role-borgbackup/commit/7fc5fe2dcb89c171d37beec6a02d42b217a44d84

artybdrlt commented 5 months ago

I second that comment. I also came across this warning message this morning with my latest borg-related project.