mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
2a7f9f28b9
* Improve markup. * Improve filter and test guides by linking to plugins and using FQCNs more consistently. * list_merge is an option, not the filter's name. * Improve filter docs.
39 lines
1.2 KiB
ReStructuredText
39 lines
1.2 KiB
ReStructuredText
..
|
|
Copyright (c) Ansible Project
|
|
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
|
|
|
|
Working with versions
|
|
---------------------
|
|
|
|
If you need to sort a list of version numbers, the Jinja ``sort`` filter is problematic. Since it sorts lexicographically, ``2.10`` will come before ``2.9``. To treat version numbers correctly, you can use the :ansplugin:`community.general.version_sort filter <community.general.version_sort#filter>`:
|
|
|
|
.. code-block:: yaml+jinja
|
|
|
|
- name: Sort list by version number
|
|
debug:
|
|
var: ansible_versions | community.general.version_sort
|
|
vars:
|
|
ansible_versions:
|
|
- '2.8.0'
|
|
- '2.11.0'
|
|
- '2.7.0'
|
|
- '2.10.0'
|
|
- '2.9.0'
|
|
|
|
This produces:
|
|
|
|
.. code-block:: ansible-output
|
|
|
|
TASK [Sort list by version number] ********************************************************
|
|
ok: [localhost] => {
|
|
"ansible_versions | community.general.version_sort": [
|
|
"2.7.0",
|
|
"2.8.0",
|
|
"2.9.0",
|
|
"2.10.0",
|
|
"2.11.0"
|
|
]
|
|
}
|
|
|
|
.. versionadded: 2.2.0
|