roles-ansible/ansible_role_restic

wish: drop dependency on jmespath

markstos opened this issue · 4 comments

This tool is only used for a single json_query() call, and that call only exists to support specifying backups as either an array or a dict.

The role already works fine without the dependency, by specifying the structure as an array. When it's used, it seems it's primary converting the structure back an array anyway.

This change could be made in a backwards compatible way by checking for the list structure first, and only loading the dict structure (and thus the jmespath dependency for those using the object format).

Alternatively, perhaps a simple filter could be added instead of loading another dependency. A vars plugin might work, to transform one structure into another, or perhaps a filter plugin.


def flatten_top_level(data):
  """
  Filters a YAML array of nested objects to just the top level key values.
  """
  return [x.values() for x in data]

This might replace the JSON filter as well:

{{ restic_backups | default([]) | map('extract', restic_backups) | list }}

I've confirmed this filter does transfer a dict into the array of the values of the top-level keys, but I haven't installed to jmespath to confirm that it's doing precisely the same thing.

hi @markstos

At the moment I don't have enough time to give this Ansible role the attention it deserves.

Would you perhaps like to submit this as a pull request yourself? Otherwise I'll have to see when I can find the time, but I don't want to promise a date...

Thanks for sharing the role. I can submit this PR.

PR submitted. Backup software is something that we hope will work 10 or 20 or 30 years later. Reducing dependencies reduces complexity and increases the odds that we'll be able to install and use the software when we need to.

For example, I just tried to install python-jmespath on Arch Linux to complete this PR, but it failed! Some other unmanaged tool had installed a conflicting file, but i couldn't figure out how. I eventuall just brute-force removed /usr/bin/jp.py (🙈), which perhaps will break something else. Once the dep is dropped, other people won't run into a situation like that.