When would you pick `include_tasks` over `import_tasks`?
IntermediateScenarioRoles, Collections and Project Structure
Answer
Situation read → Static vs dynamic reuse.
What I'd do → Use include_tasks when the file name depends on a variable, when you loop over the include, or when you need when applied once at runtime. Use import_tasks when you want tags and --list-tasks to see everything.
- ansible.builtin.include_tasks: "{{ ansible_facts['os_family'] }}.yml"
Why → Imports are expanded before the run; includes are evaluated as the play reaches them, so tags on the include apply only to the include itself.
Interview tip → --list-tasks does not show tasks inside dynamic includes.
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