A role is used twice with different parameters in one play, but only runs once.
IntermediateScenarioRoles, Collections and Project Structure
Answer
Situation read → Role de-duplication.
What I'd do → Set allow_duplicates: true in the role's meta/main.yml, or use include_role with vars.
# meta/main.yml
allow_duplicates: true
- ansible.builtin.include_role: { name: vhost, vars: { site: a.example.com } }
- ansible.builtin.include_role: { name: vhost, vars: { site: b.example.com } }
Why → Roles with identical parameters are deduplicated by default.
Interview tip → A loop over include_role is another common pattern.
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`.BeginnerYou 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?IntermediateA role installs a package and writes a config, but must support Ubuntu and Rocky Linux.Intermediate