What are handlers and when do they run?
⚡
Quick Answer
Handlers are tasks triggered by notify that run once, at the end of the play, only if a notifying task reported changed.
Detailed Answer
A common pattern: a template task deploys a config and notifies 'Restart nginx'. The handler runs only if the file actually changed, and only once even if notified multiple times. Handlers run after all tasks in the play by default (use meta: flush_handlers to run them earlier).
Code Example
handlers:
- name: Restart nginx
ansible.builtin.service:
name: nginx
state: restarted💡
Interview Tip
Emphasize 'only on change, only once' — a classic interview point.
ansiblehandlersnotify