I was a bit puzzled when trying to use version_compare Jinja filter to
check that the major and minor Ansible versions are equal to some
desired value.
Here is an example playbook:
- hosts: localhost
connection: local
gather_facts: false
vars:
- ansible_ver: "2.1.2"
tasks:
- name: Check that Ansible major and minor versions are the same
debug: msg="{{ ansible_ver | version_compare('2.1', '==') }}"
# returns 'false' but I would expect it to return 'true'
\- name: Check that Ansible major and minor versions are the same
debug: msg="\{\{ ansible\_ver | version\_compare\('2\.1', '==',
strict=True) }}"
# returns 'false' as expected
(Note: In real playbooks, one would use ansible_version.full in place
of ansible_ver.)
Is this a bug or intended behavior?
If the second, how would one do comparisons that would only compare the
major and minor version, ignoring the patch level? Or achieve something
like Python's compatible release operator (~=) [1]?
Also, I don’t think strict does what you think it means (it’s more likely to allow
non PEP-compliant versions to be compared, akin to distutils LooseVersion
vs StrictVersion)