Quiz Entry - updated: 2026.11.26
A main playbook first defines "Play 1" and then imports play2.yml. In which order does Ansible run them?
Top to bottom: Play 1 runs first, then the plays from play2.yml.
* After parsing, the import is replaced by the plays from the file, in place. *
- name: Play 1
hosts: localhost
tasks:
- name: Display a message
ansible.builtin.debug:
msg: Play 1
- name: Import Playbook
ansible.builtin.import_playbook: play2.yml
You can freely alternate plays written in the main file with imported playbooks. Because the import is static, Ansible replaces the import line with the plays from play2.yml while parsing, and the result is one flat list of plays that runs in order. Where the import sits is where its plays run.
Go deeper:
ansible.builtin.import_playbook module (official docs) โ the module reference, including why it can't be used inside a play.