Note also that "~=" isn't a valid operator for version_compare
https://docs.ansible.com/ansible/playbooks_tests.html#version-comparison
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)
On Tuesday, October 25, 2016 at 11:50:35 PM UTC+10, Will Thames wrote:
>
> I would not expect "2.1.2"|version_compare('2.1', '==') to return true as
> they are not equal.
>
> For what you want, you could use
>
> ansible_ver | version_compare('2.1', '>=') and ansible_ver |
> version_compare('2.2', '<')
>
> On Tuesday, October 25, 2016 at 10:58:46 PM UTC+10, Tadej Janež wrote:
>>
>> Hi!
>>
>> 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]?
>>
>> Thanks and regards,
>> Tadej Janež
>>
>> [1] https://www.python.org/dev/peps/pep-0440/#compatible-release
>>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.