Firing handlers after error

Hello,

When adjusting playbooks, it sometimes happen that something fails. The problem is that it stops everything, including handlers that were to be run because of past successful tasks.
Then, I fix the problem, and run the playbook again. Tasks that succeeded are now in state “ok”, and handlers are not run. But they were not run in the past run. And I have no way to have then run except doing it manually or forcing the tasks to be executed again (i.e. taking time to find which tasks succeeded the first time and have a handler and do something…).

Is there any good reason for not running handlers that have been triggered by successful tasks if a following task fails ?

“Is there any good reason for not running handlers that have been triggered by successful tasks if a following task fails ?”

Many many reasons.

For instance, if a step was “template this file with a validation step” and the validation failed, it’s a terribly bad idea to reload
a service when it’s going to fail.

Hello,

Sorry for having been in another world for so long.

“Is there any good reason for not running handlers that have been triggered by successful tasks if a following task fails ?”

Many many reasons.

For instance, if a step was “template this file with a validation step” and the validation failed, it’s a terribly bad idea to reload
a service when it’s going to fail.

Understood.

What about an option to ansible-playbook asking to only run a handler ?
That would be nice also to display, after an error, all the handlers that would have been triggered, and even nicer to give the command line to copy/paste to have one of those handlers fired.

Proposed use case:

$ ansible-playbook mybook.yml
[…]

PLAY RECAP ********************************************************************
to retry, use: --limit @xxx/mybook.retry

1.2.3.4 : ok=0 changed=0 unreachable=0 failed=1

Handlers that were notified but not fired:
1.2.3.4:
my handler 1:
ansible-playbook mybook.yml --only-handler “my handler 1” --limit 1.2.3.4
my handler 2:
ansible-playbook mybook.yml --only-handler “my handler 2” --limit 1.2.3.4

At this stage, I can choose to run handlers which are needed:

$ ansible-playbook mybook.yml --only-handler “my handler 2” --limit 1.2.3.4