Interview Prep/Ansible/Playbooks, Plays, Tasks and Handlers

What happens to pending handlers when a task fails?

AdvancedConceptPlaybooks, Plays, Tasks and Handlers
Answer

By default, when a task fails on a host, that host is removed from the rest of the play and its already-notified handlers do not run. The result can be a changed config file with the service still running the old config, and the next run sees no change, so the handler never fires.

Fix with force_handlers: true in the play, --force-handlers on the CLI, or ANSIBLE_FORCE_HANDLERS. Another safe pattern is to avoid the problem: reload with meta: flush_handlers right after the config task. unreachable hosts still do not run handlers.

All Ansible questions Roadmap: Ansible

More on Playbooks, Plays, Tasks and Handlers