Introduction Ansible handlers are special tasks that only run when notified by other tasks. When handlers do not trigger as expected, services may not restart after configuration changes, leaving systems in inconsistent states.
Symptoms - Configuration changes applied but service not restarted - Handler listed in playbook output but shows "skipping" - "ERROR! The requested handler was not found" - Handlers run in unexpected order - Handlers not running after failed tasks
Common Causes - Handler name mismatch between notify and handler definition - Handler defined in wrong file or not included - Task does not report "changed" status (handler only runs on change) - Playbook fails before handler execution - Multiple handlers with same name (only first one runs)
Step-by-Step Fix 1. **Verify handler names match notify exactly**: ```yaml # Task - name: Update config copy: src: nginx.conf dest: /etc/nginx/nginx.conf notify: Restart Nginx
# Handler (name must match exactly) - name: Restart Nginx service: name: nginx state: restarted ```
- 1.Force handlers to run even on playbook failure:
- 2.```bash
- 3.ansible-playbook site.yml --force-handlers
- 4.
` - 5.Listen for multiple events with same handler:
- 6.```yaml
- 7.handlers:
- 8.- name: Restart services
- 9.listen: "restart web"
- 10.service:
- 11.name: "{{ item }}"
- 12.state: restarted
- 13.loop: [nginx, php-fpm]
- 14.
`