ansible-role-borgbackup icon indicating copy to clipboard operation
ansible-role-borgbackup copied to clipboard

config.yaml syntax deprecated

Open sinux-l5d opened this issue 1 year ago • 8 comments

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://[email protected]/./repo"
    [...]
- import_role:  borgbase.ansible_role_borgbackup
  vars:
    borg_repository: 
        - "ssh://[email protected]/./repo"
    [...]
- import_role:  borgbase.ansible_role_borgbackup
  vars:
    borg_repository:
        - path: "ssh://[email protected]/./repo"
          label: default
    [...]
- import_role:  borgbase.ansible_role_borgbackup
  vars:
    borg_repository:
        path: "ssh://[email protected]/./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

sinux-l5d avatar Feb 09 '24 17:02 sinux-l5d

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

artybdrlt avatar Mar 22 '24 08:03 artybdrlt

We may need a way to version the config file template used. Some more changes since this was opened:

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: before_backup is deprecated and support will be removed from a future release. Use commands: instead.
/etc/borgmatic/config.yaml: after_backup is deprecated and support will be removed from a future release. Use commands: instead.
/etc/borgmatic/config.yaml: on_error is deprecated and support will be removed from a future release. Use commands: instead.
/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.
/etc/borgmatic/config.yaml: The repositories option now expects a list of key/value pairs. Lists of strings for this option are deprecated and support will be removed from a future release.

m3nu avatar May 04 '25 15:05 m3nu

I would like to fix this!

I identified issue #139 as being about the same topic, but this issue here is more general about deprecated config options.

Pull request #135 fixes many things, but does not implement versioned config templates and cannot be merged currently.

If you want I could submit a new pull request implementing this?

MaxValue avatar May 27 '25 20:05 MaxValue

I am working on this right now

MaxValue avatar Jul 18 '25 12:07 MaxValue

So I have determined the different config versions, now I am building the logic for selecting the correct template. Question @m3nu: do we prefer:

  • hardcoded versions in the tasks file which the installed version gets compared against (downside: each new config version adds a line here so changes have to be made in 2 places)
  • the tasks file looks up which config templates exist and compares against those dynamically (would use the magic var role_path which is supported since ansible 1.8)

MaxValue avatar Jul 19 '25 14:07 MaxValue

Could it somehow work with with_first_found to go from more to less specific? Like we do for OS vars.

This is the trickiest problem of the project, I think. Would even ask a LLM to see if it comes up with something we have missed for this use case.

m3nu avatar Jul 19 '25 16:07 m3nu

I thought along the same lines!

Actually now that I think about it again - it's possible with with_first_found.

I asked an LLM but it only gave me the hardcoding solution. But I am bad at vibe coding I have to say. I usually don't use LLMs at all.

MaxValue avatar Jul 19 '25 17:07 MaxValue

But I am bad at vibe coding I have to say. I usually don't use LLMs at all.

Also wouldn't recommend it. But might have been good for brainstorming.

m3nu avatar Jul 19 '25 20:07 m3nu