Ansible - roles and tasks execution handling in playbook

28 views
Skip to first unread message

Ankur Gupta

unread,
May 7, 2018, 12:36:53 PM5/7/18
to Ansible Project

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'] }}"

Edmund Cheng

unread,
May 7, 2018, 10:22:18 PM5/7/18
to Ansible Project
Did you maybe try with serial and max_fail_percentage?

Ankur Gupta

unread,
May 8, 2018, 12:25:33 AM5/8/18
to Ansible Project
both serial and max_fail_percentage do not work for this case. because I need to skip the remaining roles.

Kai Stian Olstad

unread,
May 12, 2018, 3:40:24 PM5/12/18
to ansible...@googlegroups.com
On 08.05.2018 06:25, Ankur Gupta wrote:
> both serial and max_fail_percentage do not work for this case. because
> I
> need to skip the remaining roles.

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.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages