Elaborating a bit, see https://natsort.readthedocs.io/en/master/index.html.

First "pip install natsort".
Then create filters.py:

from jinja2._compat import string_types
# Custom filter for use with Jinja2
def natsort(arg):
    from natsort import natsorted
    return natsorted(arg)
class FilterModule(object):
    def filters(self):
        return {
                'natsort': natsort
                }

and store it in your filters path (see 'ansible-config dump | grep
DEFAULT_FILTER_PLUGIN_PATH').


Now you can just use "{{ my_version|natsort }}" which gives the order
you're looking for.

Dick




On 22 August 2018 at 17:00, Brian Coca <[email protected]> wrote:
> Currently we have http://jinja.pocoo.org/docs/2.10/templates/#sort,
> which does not seem to support a 'numeric' option. A custom filter
> would be required.
>
> --
> ----------
> Brian Coca
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/CACVha7eccJVwKxuuKNmaKpg_hdWb05TPhmu0tQBQvr_7wg8O4A%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
T: +31205304488
PGP key fingerprint: F575 58C6 62C6 FD5B A9CD 217C 2667 13D4 E6EF 488D
GÉANT Vereniging (Association) is registered with the Chamber of
Commerce in Amsterdam with registration number 40535155 and operates
in the UK as a branch of GÉANT Vereniging. Registered office:
Hoekenrode 3, 1102 BR Amsterdam, The Netherlands. UK branch address:
City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwMeL-BLE4fhJdtneJvwtqb2dh%2BfMjZ%3D9Tfz2dCKCQHTYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to