Skip to content

Commit

Permalink
Use local helper instead of community.general.version_sort.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Oct 19, 2022
1 parent 5fc7286 commit a1c6ec9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
34 changes: 34 additions & 0 deletions roles/install/filter_plugins/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2022, Felix Fontein <[email protected]>
# 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,
}
3 changes: 1 addition & 2 deletions roles/install/tasks/github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1c6ec9

Please sign in to comment.