# Correct way to use fail module and negative conditionals

**URL:** <https://forum.ansible.com/t/correct-way-to-use-fail-module-and-negative-conditionals/20050>\
**Category:** Ansible Project\
**Created:** [December 20, 2015, 4:18am UTC](https://forum.ansible.com/t/correct-way-to-use-fail-module-and-negative-conditionals/20050 "2015-12-20T04:18:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CyberCyber](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@CyberCyber](https://forum.ansible.com/u/CyberCyber)\
**Post date:** [December 20, 2015, 4:18am UTC](https://forum.ansible.com/t/correct-way-to-use-fail-module-and-negative-conditionals/20050/1 "2015-12-20T04:18:52Z")

</div>

I am trying to use the fail module at the very beginning of my playbook to check if the target server is a specific distribution and version. This way I can stop the playbook from running early on before any making any chances.

playbook:

`

---

<div class="post-metadata">

**Author:** ![CyberCyber](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@CyberCyber](https://forum.ansible.com/u/CyberCyber)\
**Post date:** [December 23, 2015, 9:44pm UTC](https://forum.ansible.com/t/correct-way-to-use-fail-module-and-negative-conditionals/20050/2 "2015-12-23T21:44:34Z")

</div>

anyone able to help ?

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [December 23, 2015, 9:59pm UTC](https://forum.ansible.com/t/correct-way-to-use-fail-module-and-negative-conditionals/20050/3 "2015-12-23T21:59:49Z")

</div>

> &nbsp;&nbsp;&nbsp;&nbsp;- name: check if target server is CentOS 6 or Ubuntu 14  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fail: msg='unsupported platform detected!'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: (ansible\_distribution != "CentOS" and  
> ansible\_distribution\_major\_version != "6") or (ansible\_distribution !=  
> "Ubuntu" and ansible\_distribution\_major\_version != "14")

This logic seems wrong to me. With

&nbsp;&nbsp;&nbsp;"msg": "distro is CentOS and version is 6"

then your when turns into

&nbsp;&nbsp;when: (False and False) or (True and True)

aka

&nbsp;&nbsp;when: False or True

aka True. Right?

I think you want something more like

&nbsp;&nbsp;when: NOT (CentOS 6 or Ubuntu 14)

than like

&nbsp;&nbsp;when: (not CentOS 6) or (not Ubuntu 14)

Because you're always going to be not one of those things -- you need to  
negate the whole or.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![CyberCyber](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@CyberCyber](https://forum.ansible.com/u/CyberCyber)\
**Post date:** [January 6, 2016, 12:53am UTC](https://forum.ansible.com/t/correct-way-to-use-fail-module-and-negative-conditionals/20050/4 "2016-01-06T00:53:52Z")

</div>

Thanks for clarifying that for me Josh.

What I did was create a variable that contains the supported distributions and have my when condition check against it:

`  
vars:  
supported\_distros: “{{ ansible\_distribution }} {{ ansible\_distribution\_major\_version }}”

tasks:

- name: check if server is running a supported distro  
fail: msg=‘Unsupported platform!’  
when: platform not in [“Ubuntu 14”,“CentOS 6”]  
`

That did the tricks!
