How do you test that a role does not break when its variable `x` is missing?
IntermediateScenarioRoles, Collections and Project Structure
Answer
Situation read → Validate input handling.
What I'd do → Add an argument_specs file so Ansible validates inputs before the role runs.
# roles/nginx/meta/argument_specs.yml
argument_specs:
main:
options:
nginx_listen_port: { type: int, default: 80 }
nginx_sites: { type: list, elements: dict, required: true }
Why → Missing or wrongly typed variables fail early with a readable message and documented defaults.
Interview tip → ansible-doc -t role can display those specs.
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