Interview Prep/Ansible/Modules, Idempotency and Handlers

`ERROR! The requested handler 'Restart nginx' was not found in either the main handlers list nor in the listening handlers list`

BeginnerTroubleshootingModules, Idempotency and Handlers
Answer

Likely causes → The name in notify: does not match the handler's name: exactly. The match is case- and space-sensitive (restart nginx against Restart nginx). Other causes: the handler lives in a different role that is not part of this play, or the role is loaded with include_role after the notify fires.

Diagnose →

grep -rn -A1 'handlers' roles/nginx/handlers/main.yml
grep -rn 'notify' roles/ | grep -i nginx

Fix → Make the names identical. Better, decouple them with listen:

# handlers/main.yml
- name: Restart nginx service
  ansible.builtin.service: {name: nginx, state: restarted}
  listen: nginx config changed
# task
notify: nginx config changed

Prevent → Use listen topics across roles. Molecule converge catches a missing handler immediately.

All Ansible questions Roadmap: Ansible

More on Modules, Idempotency and Handlers