Quiz Entry - updated: 2026.11.26
In which situations is it worth keeping groups of tasks in separate task files, and how do you organize them?
When a server setup breaks into distinct jobs, when several teams write parts of it, when some tasks are only needed under a condition, or only on one host group. Keep the files in one dedicated directory such as tasks/.
Typical cases:
- Full server setup. Creating users, installing packages, configuring services, mounting a shared file system, hardening, security updates, a monitoring agent: each becomes its own small task file that a playbook combines as needed.
- Several teams. Developers, system administrators and database administrators each write their own task files, which the person responsible for the system reviews and integrates.
- Special configuration. Tasks that only some servers need are put in a file that is included only when a condition is met.
- Host groups. Tasks that only one group of servers needs run only on hosts that belong to that group.
Keeping all task files in one directory makes it easy to see which building blocks exist, and the playbook includes or imports them by path:
tasks:
- ansible.builtin.import_tasks: tasks/users.yml
- ansible.builtin.import_tasks: tasks/packages.yml
- ansible.builtin.include_tasks: tasks/monitoring.yml
when: install_monitoring
Roles (roles/<name>/tasks/main.yml and so on) take this structure further and standardize it.
Go deeper:
Re-using Ansible artifacts (official docs) โ the four reusable artifacts: variables files, task files, playbooks and roles.