# failed\_when condition is not working

**URL:** <https://forum.ansible.com/t/failed-when-condition-is-not-working/37244>\
**Category:** Ansible Project\
**Created:** [October 19, 2022, 5:17am UTC](https://forum.ansible.com/t/failed-when-condition-is-not-working/37244 "2022-10-19T05:17:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![neha0021997](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@neha0021997](https://forum.ansible.com/u/neha0021997)\
**Post date:** [October 19, 2022, 5:17am UTC](https://forum.ansible.com/t/failed-when-condition-is-not-working/37244/1 "2022-10-19T05:17:34Z")

</div>

Hi Team,

I was trying to add one condition, in which if it should failed on that particular point. So, entire playbook should stop. Below is the written playbook.

**- hosts: all**  
**gather\_facts: yes**

**pre\_tasks:**  
**- name: Verification Step before starting the post-patch playbook**  
**pause:**  
**prompt: “You are starting post patch playbook on {{ansible\_hostname}} \n To Continue, please enter ‘YES’”**  
**register: result**

**roles:**  
**- role: add\_post\_patch\_motd**  
**failed\_when: result.user\_input != “YES”**  
**- role: qradar\_install/post\_install/python\_setup**

**- import\_playbook: patch\_cleanup.yml**  
**- import\_playbook: iso.yml**  
**- import\_playbook: post\_patch\_setup.yml**

Here, user needs to enter interactive input for the “result” variable and if entered result value is other than “YES” then role should not be called and should get failed. So, as you can see I have used failed\_when condition and based on that result value, it should not call role or get failed and entire playbook should stopped running. But now, even with failed\_when condition satisfy, the role (add\_post\_patch\_motd) is getting called. Do let me know what I am missing here.

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [October 19, 2022, 11:34am UTC](https://forum.ansible.com/t/failed-when-condition-is-not-working/37244/2 "2022-10-19T11:34:05Z")

</div>

This will always execute the role THEN fail if the condition is true. You need a different construct that only executes the condition

when: result.user\_input == “YES”

I also don’t know if you can use conditions when using roles: like this. It may only work when you use the include\_role as a task.

- tasks:
- include\_role:  
name: add\_post\_patch\_motd  
when: result.user\_input == “YES”

Walter
