# Ansible - roles and tasks execution handling in playbook

**URL:** <https://forum.ansible.com/t/ansible-roles-and-tasks-execution-handling-in-playbook/27473>\
**Category:** Ansible Project\
**Created:** [May 7, 2018, 4:36pm UTC](https://forum.ansible.com/t/ansible-roles-and-tasks-execution-handling-in-playbook/27473 "2018-05-07T16:36:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankur\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Ankur\_Gupta](https://forum.ansible.com/u/Ankur_Gupta)\
**Post date:** [May 7, 2018, 4:36pm UTC](https://forum.ansible.com/t/ansible-roles-and-tasks-execution-handling-in-playbook/27473/1 "2018-05-07T16:36:52Z")

</div>

I am working on ansible exception handling tasks and stuck in an ansible tasks execution handling problem where I need your guide to come over.

I have 2 system host group **system\_a** and **system\_b** and I develop 6 roles and each role have multiple tasks.I execute 2 roles on **syste\_a** and reaming 4 on **system\_b**.

in my case is, if any tasks in a role(1-6) are failed then skip the remains role execution and execution one task end of the playbook on system\_a group host.

How can handle this case in ansible.

Can you help me in this situation?

here is my site.yml

`

`

- host: system\_a  
roles:
- role-1
- role-2
- hosts: system\_b  
roles:
- role-3
- role-4
- role-5
- role-6
- tasks:
- name: restart postfix service  
service: name=postfix state=restarted  
delegate\_to: “{{ item }}”  
loop: “{{ groups[‘system\_a’] }}”

---

<div class="post-metadata">

**Author:** ![Edmund\_Cheng](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Edmund\_Cheng](https://forum.ansible.com/u/Edmund_Cheng)\
**Post date:** [May 8, 2018, 2:22am UTC](https://forum.ansible.com/t/ansible-roles-and-tasks-execution-handling-in-playbook/27473/2 "2018-05-08T02:22:18Z")

</div>

Did you maybe try with serial and max\_fail\_percentage?

---

<div class="post-metadata">

**Author:** ![Ankur\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Ankur\_Gupta](https://forum.ansible.com/u/Ankur_Gupta)\
**Post date:** [May 8, 2018, 4:25am UTC](https://forum.ansible.com/t/ansible-roles-and-tasks-execution-handling-in-playbook/27473/3 "2018-05-08T04:25:33Z")

</div>

both serial and max\_fail\_percentage do not work for this case. because I need to skip the remaining roles.

---

<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:** [May 12, 2018, 7:40pm UTC](https://forum.ansible.com/t/ansible-roles-and-tasks-execution-handling-in-playbook/27473/4 "2018-05-12T19:40:11Z")

</div>

Skipping the reminder roles/task is not a problem, that just a matter of setting any\_errors\_fatal: true  
The challenge is that you need to run a task afterword, but that is not supported at that level(roles), you have it on task with block/rescue.
