A role has a task that should run only if the user opts in, e.g. install the monitoring agent.
BeginnerScenarioRoles, Collections and Project Structure
Answer
Situation read → Feature toggle.
What I'd do →
# defaults/main.yml
app_enable_monitoring: false
# tasks/main.yml
- ansible.builtin.import_tasks: monitoring.yml
when: app_enable_monitoring | bool
Why → Boolean flags in defaults give a documented switch.
Interview tip → | bool guards against the string "false" passed with -e.
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