Interview Prep/Ansible/Roles, Collections and Project Structure

Your role's tasks directory has grown to a single 400-line file.

BeginnerScenarioRoles, Collections and Project Structure
Answer

Situation read → Poor readability.

What I'd do → Split into files and include them.

# tasks/main.yml
- ansible.builtin.import_tasks: install.yml
- ansible.builtin.import_tasks: configure.yml
- ansible.builtin.import_tasks: service.yml

Tag each import so users can run only configure.

Why → Small files with a clear name map to the lifecycle and are easy to review.

Interview tip → import_tasks is static (parsed upfront); include_tasks is dynamic (needed for loops or runtime filenames).

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Project Structure