Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 templating config #14

Closed
PleaseStopAsking opened this issue Jun 27, 2024 · 5 comments · Fixed by #15
Closed

v2 templating config #14

PleaseStopAsking opened this issue Jun 27, 2024 · 5 comments · Fixed by #15

Comments

@PleaseStopAsking
Copy link

I am in the process of updating my usage of this role and with the recent switch from string to yaml for the config, I am running into an issue and have been unable to workaround it myself so far.

I am leveraging Jinja2 loop to handle some locations and backends but with the new YAML change, those loops are causing issues.

I am hoping this is something simple I am missing.

Example variable:

autorestic_docker_volumes:
  - influxdb
  - scrutiny-web

Current autorestic config that worked before the yaml change

autorestic_config:
  version: 2

  locations:

  {% for volume in autorestic_docker_volumes %}
    docker-{{ volume }}:
      from: /var/lib/docker/volumes/{{ volume }}
      to: data-docker-{{ volume }}
      cron: "0 {{ loop.index }} * * 6" # every saturday at {{ loop.index }}:00

  {% endfor %}
@dbrennand
Copy link
Owner

Hi @PleaseStopAsking

Thanks for raising this issue. Similar issues to what you're seeing have been discussed in #12. Are you able to try using the lookup("template") plugin as suggested in #12 (comment) and see if that works for you?

@PleaseStopAsking
Copy link
Author

PleaseStopAsking commented Jun 27, 2024

@dbrennand I did indeed give that a shot but the generated config file was pretty rough and it wasn't clear how to solve the formatting.

"version: 2\n\nlocations:\n  docker-influxdb:\n    from: /var/lib/docker/volumes/influxdb\n
  \   to: data-docker-influxdb\n    cron: \"0 1 * * 6\" # every saturday at 1:00\n
  \   <<: *shared\n\n  docker-scrutiny-web:\n    from: /var/lib/docker/volumes/scrutiny-web\n
  \   to: data-docker-scrutiny-web\n    cron: \"0 2 * * 6\" # every saturday at 2:00\n
  \   <<: *shared\n\n"

template for reference:

version: 2

locations:
{% for volume in autorestic_docker_volumes %}
  docker-{{ volume }}:
    from: /var/lib/docker/volumes/{{ volume }}
    to: data-docker-{{ volume }}
    cron: "0 {{ loop.index }} * * 6" # every saturday at {{ loop.index }}:00
    <<: *shared

{% endfor %}

@dbrennand
Copy link
Owner

Hi @PleaseStopAsking - I've pushed the following commit 2027064

Are you able to test this version of the role on branch issue/#12?

@PleaseStopAsking
Copy link
Author

@dbrennand This change does appear to solve the problem.

Below is the usage just for reference.

  roles:
    - role: dbrennand.autorestic
      vars:
        autorestic_version: "{{ autorestic_version_override }}"
        autorestic_restic_version: "{{ autorestic_restic_version_override }}"
        autorestic_info: true
        autorestic_check: true
        autorestic_cron: true
        autorestic_cron_verbose: true
        autorestic_state: present
        autorestic_config_template: ../templates/autorestic.j2

@dbrennand
Copy link
Owner

@dbrennand This change does appear to solve the problem.

Below is the usage just for reference.

  roles:
    - role: dbrennand.autorestic
      vars:
        autorestic_version: "{{ autorestic_version_override }}"
        autorestic_restic_version: "{{ autorestic_restic_version_override }}"
        autorestic_info: true
        autorestic_check: true
        autorestic_cron: true
        autorestic_cron_verbose: true
        autorestic_state: present
        autorestic_config_template: ../templates/autorestic.j2

That's great news. Thank you for testing @PleaseStopAsking 🙂

I think we can move forward with this implementation because the user can either override the template themselves, as you've done here, or they can continue using autorestic_config and it will be templated in the end anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants