# set\_fact not working with when condition

**URL:** <https://forum.ansible.com/t/set-fact-not-working-with-when-condition/30183>\
**Category:** Ansible Project\
**Created:** [April 24, 2019, 9:56pm UTC](https://forum.ansible.com/t/set-fact-not-working-with-when-condition/30183 "2019-04-24T21:56:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [April 24, 2019, 9:56pm UTC](https://forum.ansible.com/t/set-fact-not-working-with-when-condition/30183/1 "2019-04-24T21:56:25Z")

</div>

I have a role, and in the **defaults/main.yml** I have the following variable set:

`

---

<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:** [April 24, 2019, 10:06pm UTC](https://forum.ansible.com/t/set-fact-not-working-with-when-condition/30183/2 "2019-04-24T22:06:01Z")

</div>

ansible\_distribution\_major\_version is a string, and you are comparing it to an integer of 6.

You can do one of a few things:

when: ansible\_distribution\_major\_version|int \> 6

or

when: ansible\_distribution\_major\_version is version(‘6’, ‘gt’)

[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_tests.html#version-comparison](https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#version-comparison)

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [April 24, 2019, 10:15pm UTC](https://forum.ansible.com/t/set-fact-not-working-with-when-condition/30183/3 "2019-04-24T22:15:52Z")

</div>

Ah, great thanks Matt! I went down that path before submitting this, but my syntax was wrong. Thanks again!
