Quiz Entry - updated: 2026.11.26
What does ansible.builtin.import_playbook do, and where in a playbook may it appear?
It pulls a whole other playbook (its list of plays) into a main playbook. It may only stand at the top level, as an entry in the list of plays, never inside a play.
- name: Prepare the web server
ansible.builtin.import_playbook: web.yml
- name: Prepare the database server
ansible.builtin.import_playbook: db.yml
The imported files are complete playbooks: each contains plays with their own hosts:, tasks: and so on. That is why the import must sit where plays sit. A play's tasks: list can hold tasks, not plays, so putting import_playbook under tasks: is an error.
The imported playbooks run in the order they are listed, as if their plays had been written directly into the main file. This makes a "site" playbook possible that sets up a whole environment by combining small, focused playbooks.
Go deeper:
ansible.builtin.import_playbook module (official docs) — the module reference, including why it can't be used inside a play.
Reusing playbooks (official docs) — import_playbook, choosing the file with --extra-vars or vars.