@cglacet answer was useful and worked when generating in Ansible, but it gave me an error when using the Jinja2 library directly in Python:
Exception has occurred: TypeError
'>=' not supported between instances of 'generator' and 'generator'
It seems like it prints the memory location and not actual values. I don't know what voodoo magic Ansible used to make it work, but adding a | list
creates an actual list of integers and fixes the issue.
{% if current_version.split('.') | map('int') | list < '10.9.8'.split('.') | map('int') | list %}
Proof:
{% set sw_version = "7.5.2" %}
{{ sw_version.split('.') }}
{{ ['7', '5', '2'] | int }}
{{ sw_version.split('.') | map('int') }}
output
['7', '5', '2']
0
<generator object sync_do_map at 0x1223b6270>
Fix:
{% set sw_version = "7.5.2" %}
{% if sw_version.split('.') | map('int') | list < '10.9.8'.split('.') | map('int') | list %}
Smaller than to 10.9.8
{% endif %}
{% if sw_version.split('.') | map('int') | list >= '7.5.2'.split('.') | map('int') | list %}
Equal to 7.5.2
{% endif %}
{% if sw_version.split('.') | map('int') | list >= '6.7.5'.split('.') | map('int') | list %}
Bigger than 6.7.5
{% endif %}
{% if sw_version.split('.') | map('int') | list < '7.6.1'.split('.') | map('int') | list %}
Smaller than 7.6.1
{% endif %}
{% if sw_version.split('.') | map('int') | list < '7.5.10'.split('.') | map('int') | list %}
Smaller than 7.5.10
{% endif %}
Smaller than to 10.9.8
Equal to 7.5.2
Bigger than 6.7.5
Smaller than 7.6.1
Smaller than 7.5.10