Interview Prep/Ansible/Roles, Collections and Project Structure

A role requires a handler from another role.

AdvancedScenarioRoles, Collections and Project Structure
Answer

Situation read → Cross-role notification.

What I'd do → Handlers are global to the play, so a task can notify by name. But this couples roles; better to use listen topics.

# role A
notify: "reload web stack"
# role B handler
- name: Reload nginx
  ansible.builtin.service: { name: nginx, state: reloaded }
  listen: "reload web stack"

Why → A topic name is a stable contract; handler names are not.

Interview tip → Include roles dynamically with include_role and handlers become visible only after that point.

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Project Structure