community.general.version_sort filter – Sort a list according to version order instead of pure alphabetical one

Note

This filter plugin is part of the community.general collection (version 9.4.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.version_sort.

New in community.general 2.2.0

Synopsis

  • Sort a list according to version order instead of pure alphabetical one.

Input

This describes the input of the filter, the value before | community.general.version_sort.

Parameter

Comments

Input

list / elements=string / required

A list of strings to sort.

Examples

- name: Convert list of tuples into dictionary
  ansible.builtin.set_fact:
    dictionary: "{{ ['2.1', '2.10', '2.9'] | community.general.version_sort }}"
    # Result is ['2.1', '2.9', '2.10']

Return Value

Key

Description

Return value

list / elements=string

The list of strings sorted by version.

Returned: success

Authors

  • Eric L. (@ericzolf)

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.