Roles in your repo access each other's internal variables. How do you reduce coupling?
IntermediateScenarioRoles, Collections and Project Structure
Answer
Situation read → Tight coupling.
What I'd do →
- Define a clear public interface in
defaults/andargument_specs. - Pass data in via role parameters, not by reading another role's vars.
- Share common facts via a
commonrole or inventory variables.
Why → Roles that only depend on declared inputs are replaceable and testable alone.
Interview tip → Say "a role is a function: inputs in defaults, effects on the host".
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