diff --git a/roles/install/filter_plugins/helpers.py b/roles/install/filter_plugins/helpers.py new file mode 100644 index 00000000..42ea5e8d --- /dev/null +++ b/roles/install/filter_plugins/helpers.py @@ -0,0 +1,34 @@ +# Copyright (c) 2022, Felix Fontein +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +from ansible.module_utils.six import raise_from + +try: + from ansible.module_utils.compat.version import LooseVersion +except ImportError: + try: + from distutils.version import LooseVersion + except ImportError as exc: + msg = ( + 'To use this plugin or module with ansible-core 2.11, ansible-base 2.10,' + ' or Ansible 2.9, you need to use Python < 3.12 with distutils.version present' + ) + raise_from(ImportError(msg), exc) + + +def pick_latest_version(version_list): + '''Pick latest version from a list of versions.''' + return sorted(version_list, key=LooseVersion, reverse=True)[0] + + +class FilterModule(object): + '''Helper filters.''' + def filters(self): + return { + '_community_sops_install_pick_latest_version': pick_latest_version, + } diff --git a/roles/install/tasks/github.yml b/roles/install/tasks/github.yml index 10d96667..1447ac8d 100644 --- a/roles/install/tasks/github.yml +++ b/roles/install/tasks/github.yml @@ -29,8 +29,7 @@ | rejectattr("draft") | map(attribute="tag_name") | map("regex_replace", "^v", "") - | community.general.version_sort - | last + | _community_sops_install_pick_latest_version }} - name: Show selected version