You want to share roles across several repos and teams.
IntermediateScenarioRoles, Collections and Project Structure
Answer
Situation read → Distribution and versioning.
What I'd do →
- Package roles in a collection (
namespace.collection) or keep one repo per role. - Pin versions in
requirements.yml.
collections:
- name: acme.platform
version: 1.4.2
source: https://galaxy.internal.example.com
roles:
- src: git+https://git.example.com/ansible/nginx.git
version: v2.1.0
name: acme.nginx
Install with ansible-galaxy install -r requirements.yml.
Why → Pinned versions give reproducible builds.
Interview tip → Use a private Galaxy/Automation Hub or Artifactory for internal content.
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.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