`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.
More on Modules, Idempotency and Handlers
A handler named `restart {{ app_service }}` is never found when notified as `restart myapp`AdvancedA `command` task reports `changed` on every run, and the Molecule idempotence check failsBeginner`curl ... | tar xz` fails on the host but the `shell` task reports successIntermediate`lineinfile` appends the same line again on every runIntermediate`lineinfile` with `backrefs: true` reports `ok` but the line was never addedIntermediateA `template` task reports `changed` and restarts the service on every runIntermediate