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.
More on Roles, Collections and Project Structure
You have a 600-line playbook that sets up web, db and monitoring. How do you restructure it?BeginnerWhere do you put a variable users of your role are expected to override?BeginnerTwo roles need to run in a fixed order, such as `common` before `nginx`.BeginnerA role is used twice with different parameters in one play, but only runs once.IntermediateYou want to share roles across several repos and teams.IntermediateHow do you pin Ansible itself so a CI run today behaves like one last month?Intermediate