# When ... "ansible\_facts\['distribution\_major\_version'\] \<= '9')" evaluates not as expected

**URL:** <https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475>\
**Category:** Get Help\
**Tags:** redhat\
**Created:** [June 19, 2025, 9:01am UTC](https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475 "2025-06-19T09:01:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nesbit7](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nesbit7](https://forum.ansible.com/u/Nesbit7)\
**Post date:** [June 19, 2025, 9:01am UTC](https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475/1 "2025-06-19T09:01:21Z")

</div>

Hi,

RedHat 10 was released in May, and to address subtle differences between RedHat 9 and 10 I thought I could simply use the ‘lte’ construct for RedHat 9:-

```auto
     when: (ansible_facts['distribution'] == 'RedHat' and ansible_facts['distribution_major_version'] <= '9') or
           (ansible_facts['distribution'] == 'OracleLinux' and ansible_facts['distribution_major_version'] <= '9')

and for RedHat 10 use the following to differentiate:-

```

```
 when: (ansible_facts['distribution'] == 'RedHat' and ansible_facts['distribution_major_version'] == '10') or
       (ansible_facts['distribution'] == 'OracleLinux' and ansible_facts['distribution_major_version'] == '10')

```

however, the less than or equal to 9 is evaluating to true for my RedHat 10 deployments, so still tries to run the wrong code and consequently fails.

I wonder is this because the first character ‘1’ of ‘10’ is being evaluated as less than 9, whereas I expect this to evaluate to false. Probably wrong on that, but I’ve tried int without improving things.

Any ideas?

---

<div class="post-metadata">

**Author:** ![mkrizek](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mkrizek/32/2055_2.png) [@mkrizek](https://forum.ansible.com/u/mkrizek)\
**Post date:** [June 19, 2025, 10:37am UTC](https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475/2 "2025-06-19T10:37:44Z")

</div>

What the current code does is lexicographical comparison. You want to operate on integers, not strings:

```auto
ansible_facts['distribution_major_version'] | int <= 9

```

---

<div class="post-metadata">

**Author:** ![Nesbit7](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nesbit7](https://forum.ansible.com/u/Nesbit7)\
**Post date:** [June 19, 2025, 12:49pm UTC](https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475/3 "2025-06-19T12:49:10Z")

</div>

thanks @mkrizek [Martin]

I thought I tried to int already, but evidently didn’t have it quite right.

i can confirm your solution worked,

thanks for the quick response,

best regards,

---

<div class="post-metadata">

**Author:** ![tonk](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tonk/32/214_2.png) [@tonk](https://forum.ansible.com/u/tonk)\
**Post date:** [June 19, 2025, 1:15pm UTC](https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475/4 "2025-06-19T13:15:20Z")

</div>

In fact versions should not be checked like that, but better with the `version` filter

```auto
when: ansible_facts['distribution'] | version('9', ' <=')

```

---

<div class="post-metadata">

**Author:** ![Nesbit7](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nesbit7](https://forum.ansible.com/u/Nesbit7)\
**Post date:** [June 19, 2025, 1:30pm UTC](https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475/5 "2025-06-19T13:30:54Z")

</div>

OK thanks , Ton, I’ll give that a go, ta

---

<div class="post-metadata">

**Author:** ![mkrizek](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mkrizek/32/2055_2.png) [@mkrizek](https://forum.ansible.com/u/mkrizek)\
**Post date:** [June 19, 2025, 2:06pm UTC](https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475/6 "2025-06-19T14:06:27Z")

</div>

`version` is a test (plugin), not a filter so the correct form would be:

```auto
ansible_facts['distribution_version'] is version('9', '<=')

```

In general when using the `version` test, make sure you have the correct versioning scheme (if available) set for your use case: [ansible.builtin.version test – compare version strings — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/version_test.html#parameter-version_type).

Though I don’t see a problem with checking against `distribution_major_version` directly if the major version is the only relevant part.

---

<div class="post-metadata">

**Author:** ![tonk](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tonk/32/214_2.png) [@tonk](https://forum.ansible.com/u/tonk)\
**Post date:** [June 20, 2025, 8:05am UTC](https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475/7 "2025-06-20T08:05:15Z")

</div>

Yes, you are right.

Just checked in a tiny playbook

---

<div class="post-metadata">

**Author:** ![Nesbit7](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nesbit7](https://forum.ansible.com/u/Nesbit7)\
**Post date:** [June 20, 2025, 10:02am UTC](https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475/8 "2025-06-20T10:02:05Z")

</div>

thanks people, yes this later amendment also works, so also marked as solved, thanks again.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 20, 2025, 10:02am UTC](https://forum.ansible.com/t/when-ansible-facts-distribution-major-version-9-evaluates-not-as-expected/43475/9 "2025-07-20T10:02:29Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
