A handler named `restart {{ app_service }}` is never found when notified as `restart myapp`
AdvancedTroubleshootingModules, Idempotency and Handlers
Answer
Likely causes → Handler names are templated once, when handlers are loaded, using only the variables available at that point (play vars, role defaults and vars, extra vars). If app_service comes from inventory, set_fact or include_vars, the name does not render the way you expect, and the notify does not match.
Fix → Give the handler a static name, template the module arguments instead, and use listen:
- name: Restart application
ansible.builtin.systemd:
name: "{{ app_service }}"
state: restarted
listen: app restart needed
Prevent → Never template handler names or notify strings. Keep names static and parameters dynamic.
More on 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`BeginnerA `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