# issue with stopping the playbook

**URL:** <https://forum.ansible.com/t/issue-with-stopping-the-playbook/28873>\
**Category:** Ansible Project\
**Created:** [October 25, 2018, 9:28pm UTC](https://forum.ansible.com/t/issue-with-stopping-the-playbook/28873 "2018-10-25T21:28:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![itssitaram9](https://avatars.discourse-cdn.com/v4/letter/i/4bbf92/32.png) [@itssitaram9](https://forum.ansible.com/u/itssitaram9)\
**Post date:** [October 25, 2018, 9:28pm UTC](https://forum.ansible.com/t/issue-with-stopping-the-playbook/28873/1 "2018-10-25T21:28:29Z")

</div>

hello,

I have playbook that imports multiple sub play books. Basically, i want the main playbook to shut down the servers sequentially…

main play book:

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 26, 2018, 6:37am UTC](https://forum.ansible.com/t/issue-with-stopping-the-playbook/28873/2 "2018-10-26T06:37:31Z")

</div>

> main play book:
> 
> ---  
> - hosts: all  
> &nbsp;&nbsp;remote\_user: test  
> &nbsp;&nbsp;become: yes  
> &nbsp;&nbsp;connection: ssh  
> &nbsp;&nbsp;gather\_facts: false  
> &nbsp;&nbsp;#ignore\_errors: no  
> &nbsp;&nbsp;#any\_errors\_fatal: true

You need to enable any\_errors\_fatal.

> ===============================================================================  
> &nbsp;&nbsp;&nbsp;second.yml
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- name: execute stopEG.sh and shutdown  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: /home/test/stopEG.sh  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: script\_output
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: script\_output

You can use the fail module to stop.

- fail:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "Stopping because of a failure"  
&nbsp;&nbsp;&nbsp;when: script\_output.failed

> &nbsp;&nbsp;&nbsp;&nbsp;- name: shutdown the server now  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: shutdown -h now  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: not script\_output.failed
> 
> (logins to the second server if the script has a execute code of 1, it will  
> not shutdown the server.)

\<snip /\>

> My issue is with the second.yml file i have an exit code of 1, i want the  
> main playbook to be stopped at the end of second.yml but instead it is just  
> skipping the shutdown in second.yml and shutting down the servers in third  
> and fourth playbooks.
> 
> All i want is playbook to be stopped if there is an error and not shut the  
> other servers down!

With the proposed changes above this should be the desire effect.

---

<div class="post-metadata">

**Author:** ![itssitaram9](https://avatars.discourse-cdn.com/v4/letter/i/4bbf92/32.png) [@itssitaram9](https://forum.ansible.com/u/itssitaram9)\
**Post date:** [October 26, 2018, 1:03pm UTC](https://forum.ansible.com/t/issue-with-stopping-the-playbook/28873/3 "2018-10-26T13:03:13Z")

</div>

if i enable the any\_errors\_fatal, if there is no error in the script and if it executes second.yml, it shut downs the server.  
when the server is unreachable. because of the any\_errors\_fatal the script stops at second.yml.

i want the script to run third.yml and fouth.yml if there is no error in the second.yml.
