I'm running Ansible 2.0, and I could just run this, but I could also be tricked in to believing something that isn't true by my empirical tests and I can find no documentation to tell me when handlers are supposed to be ran.
If handlers aren't ran at the end of their tasks, this is my conundrum. I've got a playbook with 5 roles in it, I want to add a 6 role to the end that needs to have the handlers of the 4th role completed before it can start.
Is there any way to run Ansible to rely on a handler being completed (i.e. a role being completely completed) before doing something else or am I using handlers wrong?
Best Answer
Handlers are executed:
meta: flush_handlers
taskSo "to add a 6 role to the end that needs to have the handlers of the 4th role" you need:
or add a meta task and include the 6th role with
include_role
module:For your use case, I'd suggest the first method as the
include_role
module is still very fresh and there are quirks when using it (see this question on SO).Moreover, please notice that handlers' names and listen calls are global, so two handlers in separate roles will be in conflict if they had the same name and both roles were assigned in a single play. (ref. Handlers: Running Operations On Change)
Empirical proof (run this shell script to confirm handlers are executed at the end of the play - there were contradicting comments and answers here):
Result:
Play modified to contain
meta: flush_handlers
:The result: