While it is possible to write a playbook in one very large file (and you might start out learning playbooks this way), eventually you'll want to reuse files and start to organize things. In Ansible, there are three ways to do this: includes, imports, and roles.
Includes and imports allow users to break up large playbooks into smaller files, which can be used across multiple parent playbooks or even multiple times within the same Playbook.
Includes and imports (added in 2.4) allow users to break up large playbooks into smaller files, which can be used across multiple parent playbooks or even multiple times within the same Playbook.
Roles allow more than just tasks to be packaged together and can include variables, handlers, or even modules and other plugins. Unlike includes and imports, roles can also be uploaded and shared via Ansible Galaxy.
@ -13,17 +13,25 @@ As noted in :doc:`playbooks_reuse`, include and import statements are very simil
Please refer to :doc:`playbooks_reuse` for documentation concerning the trade-offs one may encounter when using each type.
Also be aware that this behaviour changed in 2.4; prior to that Ansible version only ``include`` was available, and it behaved differently depending on context.
..versionadded:: 2.4
Importing Playbooks
```````````````````
It is possible to include playbooks inside a master playbook. For example::
---
import_playbook: webservers.yml
import_playbook: databases.yml
- import_playbook: webservers.yml
- import_playbook: databases.yml
The plays and tasks in each playbook listed will be run in the order they are listed, just as if they had been defined here directly.
Prior to 2.4 only ``include`` was available and worked for both playbooks and tasks as both import and include.
Each playbook listed will be run in the order they are listed.
@ -42,7 +42,8 @@ Roles expect files to be in certain directory names. Roles must include at least
Other YAML files may be included in certain directories. For example, it is common practice to have platform-specific tasks included from the ``tasks/main.yml`` file::
# roles/example/tasks/main.yml
- import_tasks: redhat.yml
- name: added in 2.4, previouslly you used 'include'