My ansible_distribution_version returns "10". This debug fires:
- name: version 10 < 10.0
ansible.builtin.debug:
msg:
- "I think 10 is older than 10.0"
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?
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:
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.
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).
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.
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
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.
> 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:
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.