On 01. des. 2016 14:31,
sergio....@mojix.com wrote:
> Hi, I created a role that has a rescue block where role is marked as failed:
>
> --- #myrole
> - block:
> ...
> rescue:
> - fail: msg='some message' #mark as fail ansible_failed_task is defined
When ever Ansible run the fail module, it will immediately stop, no
other task will be executed for that host.
> On my playbook the idea is to send notification if ansible_failed_task is
> defined that's why "myrole" fails on rescue section. So on my playbook if
> that variable is defined I send a notification:
>
>
> - hosts: automation
> gather_facts: True
>
> post_tasks:
> - include: notification.yml status=unstable action="Tests unstable"
> when: ansible_failed_task is defined
>
> roles:
> - { role: myrole, tags: tests}
>
>
> When I run this playbook and "myrole" fails post_tasks section is never
> executed, so my question is that: Will post_tasks execute no matter whether
> role has failed or not? if not what should I use so post_tasks get executed
> no matter role's result?
The post_tasks is just a way of group tasks to be run at some sequence.
In a play you can have the following and they will run in the order they
are listed bellow
1. pre_tasks
2. roles
3. tasks
4. post_tasks
In your example when it hits fail: it will stop an no more task will be
executed.
So the rest of the roles section, tasks and post_tasks will not run for
that host.
--
Kai Stian Olstad