# "10" compares as older than "10.0" with version()

**URL:** <https://forum.ansible.com/t/10-compares-as-older-than-10-0-with-version/35740>\
**Category:** Ansible Project\
**Created:** [September 14, 2021, 11:20pm UTC](https://forum.ansible.com/t/10-compares-as-older-than-10-0-with-version/35740 "2021-09-14T23:20:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy\_Smith](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Andy\_Smith](https://forum.ansible.com/u/Andy_Smith)\
**Post date:** [September 14, 2021, 11:20pm UTC](https://forum.ansible.com/t/10-compares-as-older-than-10-0-with-version/35740/1 "2021-09-14T23:20:45Z")

</div>

Hi,

My ansible\_distribution\_version returns "10". This debug fires:

- name: version 10 \< 10.0  
&nbsp;&nbsp;ansible.builtin.debug:  
&nbsp;&nbsp;&nbsp;&nbsp;msg:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- "I think 10 is older than 10.0"  
&nbsp;&nbsp;when: {{ ansible\_distribution\_version }} is version('10.0', '\<')

python 3.9.7, ansible 2.10.14.

Any way around this without processing ansible\_distribution\_version  
to have a trailing ".0" when it has no dots?

Thanks!  
Andy

---

<div class="post-metadata">

**Author:** ![flowerysong1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@flowerysong1](https://forum.ansible.com/u/flowerysong1)\
**Post date:** [September 15, 2021, 12:49am UTC](https://forum.ansible.com/t/10-compares-as-older-than-10-0-with-version/35740/2 "2021-09-15T00:49:44Z")

</div>

Yes. Compare to the lowest version you want to accept, which is ‘10’. (Also, don’t nest moustaches.)

when: ansible\_facts.distribution\_version is version(‘10’, ‘\<’)

---

<div class="post-metadata">

**Author:** ![Andy\_Smith](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Andy\_Smith](https://forum.ansible.com/u/Andy_Smith)\
**Post date:** [September 15, 2021, 8:11am UTC](https://forum.ansible.com/t/10-compares-as-older-than-10-0-with-version/35740/3 "2021-09-15T08:11:28Z")

</div>

Hello,

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [September 15, 2021, 8:52am UTC](https://forum.ansible.com/t/10-compares-as-older-than-10-0-with-version/35740/4 "2021-09-15T08:52:23Z")

</div>

I'm not even sure if '10' and '10.0' are actually different in terms  
of one being higher or lower than the other.  
I'd be interested to know what the rationale is for declaring 10  
higher or lower than 10.0 (or the other way around).

BTW in our environment, the OSes where ansible\_distribution\_version is  
defined, it always has one or more 'decimals', for example:

9.4 (debian 9)  
10.10 (debian 10)  
16.04 (ubuntu)  
18.04 (ubuntu)  
6.9 (centos6)  
6.10 (rhel6)  
7.5.1804 (centos7)  
7.6 (rhel7)

Instead of trying to make (to me rather arbitrary) comparisons between  
10 and 10.0, I'd investigate why ansible\_distribution\_version for your  
OS has no 'decimals' to begin with.

---

<div class="post-metadata">

**Author:** ![Andy\_Smith](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Andy\_Smith](https://forum.ansible.com/u/Andy_Smith)\
**Post date:** [September 15, 2021, 7:54pm UTC](https://forum.ansible.com/t/10-compares-as-older-than-10-0-with-version/35740/5 "2021-09-15T19:54:44Z")

</div>

Hello,

> Instead of trying to make (to me rather arbitrary) comparisons between  
> 10 and 10.0, I'd investigate why ansible\_distribution\_version for your  
> OS has no 'decimals' to begin with.

I think it's because none of the point releases for Debian 10 have  
been installed on that host, so it's not received any update to the  
base-files package (for /etc/os-release) that would show the point  
release (e.g. 10.10).

$ head -3 /etc/os-release  
PRETTY\_NAME="Debian GNU/Linux 10 (buster)"  
NAME="Debian GNU/Linux"  
VERSION\_ID="10"

But this is besides the point as it is normal for a Debian release  
to show as not having decimals for some period of time. So we do have  
to be aware what testing ansible\_distribution\_version against x.0  
will do, apparently. Whether that test is newer, older or equality.

Cheers,  
Andy

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 15, 2021, 8:06pm UTC](https://forum.ansible.com/t/10-compares-as-older-than-10-0-with-version/35740/6 "2021-09-15T20:06:42Z")

</div>

FWIW, the `version` test is implemented via `distutils.version.LooseVersion` (by default)

And based on the documentation:

> there is no such thing as an invalid version number under this scheme;  
> the rules for comparison are simple and predictable, but may not always give the results you want (for some definition of “want”).

Due to the implementation details of basically comparing a python tuple, `10` is less than `10.0`

> > > LooseVersion(‘10’) \< LooseVersion(‘10.0’)  
> > > True  
> > > (10,) \< (10, 0)  
> > > True

To get equality, you’ll have to perform some normalization on your versions first, and while there are some ways you can use existing jinja operations to do so, it may require assumptions on your data that could just as easily cause problems in the future.

---

<div class="post-metadata">

**Author:** ![Andy\_Smith](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Andy\_Smith](https://forum.ansible.com/u/Andy_Smith)\
**Post date:** [September 15, 2021, 8:10pm UTC](https://forum.ansible.com/t/10-compares-as-older-than-10-0-with-version/35740/7 "2021-09-15T20:10:29Z")

</div>

Hello,

> \> Instead of trying to make (to me rather arbitrary) comparisons between  
> \> 10 and 10.0, I'd investigate why ansible\_distribution\_version for your  
> \> OS has no 'decimals' to begin with.
> 
> I think it's because none of the point releases for Debian 10 have  
> been installed on that host, so it's not received any update to the  
> base-files package (for /etc/os-release) that would show the point  
> release (e.g. 10.10).

Having now actually checked, this is not the case! That host does  
have version 10.3+deb10u10 of base-files (the latest), so I don't  
know why its /etc/os-files shows VERSION\_ID="10" or even if that is  
normal. Does yours have that? The only lsb-related packages  
installed are lsb-base and lsb-release.

Sorry, this is going off at a bit of a tangent now, but I am  
interested in why your ansible\_distribution\_version comes back as  
10.10 here!

By the way, on a freshly installed Debian 11 (bullseye) host, I also  
see:

$ head -3 /etc/os-release  
PRETTY\_NAME="Debian GNU/Linux 11 (bullseye)"  
NAME="Debian GNU/Linux"  
VERSION\_ID="11"

and that one also returns just "11" for  
ansible\_distribution\_version. So as I say, in certain configurations  
on Debian it seems normal to not have a decimal point in  
ansible\_distribution\_version.

Thanks,  
Andy
