Are ansible handlers defined in roles ran after the entire playbook or the role?

Peter Turner asked:

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?

My answer:

I routinely run playbooks which use multiple roles.

Each role that contains handlers runs those handlers at the end of that role, not at the end of the entire playbook.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.