# Conditional exit

**URL:** <https://forum.ansible.com/t/conditional-exit/16461>\
**Category:** Ansible Project\
**Created:** [October 8, 2014, 6:26am UTC](https://forum.ansible.com/t/conditional-exit/16461 "2014-10-08T06:26:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ning\_Chan](https://avatars.discourse-cdn.com/v4/letter/n/43a26b/32.png) [@Ning\_Chan](https://forum.ansible.com/u/Ning_Chan)\
**Post date:** [October 8, 2014, 6:26am UTC](https://forum.ansible.com/t/conditional-exit/16461/1 "2014-10-08T06:26:07Z")

</div>

I have an ansible script, and i want to exit 0 if some condition is met.  
How can I do it?

- name: Exit if no pkg update  
fail: msg=“No new packages for update”  
when: (ncs\_db\_ccm\_pkg\_update.rc != 100 and ncs\_db\_common\_pkg\_update.rc != 100 and  
hostvars[groups[‘server1’][0]][‘old\_yum\_result’] == “0” and  
hostvars[groups[‘server2’][0]][‘new\_yum\_result’] == “0” and  
force\_upgrade == false and upgrade == true)

Now I use fail: but this is not a good way as the return code is 3 instead of 0.

Thanks~
