# Ansible when condition check fails and does not behave as expected,

**URL:** <https://forum.ansible.com/t/ansible-when-condition-check-fails-and-does-not-behave-as-expected/31337>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [September 23, 2019, 10:26am UTC](https://forum.ansible.com/t/ansible-when-condition-check-fails-and-does-not-behave-as-expected/31337 "2019-09-23T10:26:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [September 23, 2019, 10:26am UTC](https://forum.ansible.com/t/ansible-when-condition-check-fails-and-does-not-behave-as-expected/31337/1 "2019-09-23T10:26:24Z")

</div>

> I'm expecting set\_facts not to assign values to variables when the SQL query does not yeild any results.
> 
> when condition command\_result.stdout == "" is meant for the same.
> 
> Below is my playbook.

Hello Mohtashim,

you need to use "when" instead of "failed\_when" in order to skip the set\_fact task.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
