Interview Prep/Ansible/Roles, Collections and Project Structure

You need to run roles in a loop for each tenant.

IntermediateScenarioRoles, Collections and Project Structure
Answer

Situation read → Multi-tenancy.

What I'd do →

- ansible.builtin.include_role:
    name: tenant
  vars:
    tenant_name: "{{ item.name }}"
    tenant_port: "{{ item.port }}"
  loop: "{{ tenants }}"
  loop_control: { label: "{{ item.name }}" }

Why → include_role supports loops; roles: does not.

Interview tip → Use allow_duplicates or unique params so tasks aren't skipped.

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Project Structure