How do you apply only part of a role, for instance only its configuration?
BeginnerScenarioRoles, Collections and Project Structure
Answer
Situation read → Selective execution.
What I'd do → Tag tasks and use --tags.
- ansible.builtin.template: { src: app.conf.j2, dest: /etc/app.conf }
tags: [config]
ansible-playbook site.yml --tags config
Why → Tags let you apply a slice without editing code.
Interview tip → Tags on import_tasks apply to every task inside; on include_tasks only to the include.
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