til
til copied to clipboard
What's the difference between include_tasks and import_tasks?
-
Including roles, tasks, or variables adds them to a playbook dynamically. Ansible processes included files and roles as they come up in a playbook, so included tasks can be affected by the results of earlier tasks within the top-level playbook. Included roles and tasks are similar to handlers - they may or may not run, depending on the results of other tasks in the top-level playbook.
-
Importing roles, tasks, or playbooks adds them to a playbook statically. Ansible pre-processes imported files and roles before it runs any tasks in a playbook, so imported content is never affected by other tasks within the top-level playbook.
Include_* | Import_* |
---|---|
Type of re-use | Dynamic |
When processed | At runtime, when encountered |
Task or play | All includes are tasks |
Task options | Apply only to include task itself |
Calling from loops | Executed once for each loop item |
Using --list-tags | Tags within includes not listed |
Using --list-tasks | Tasks within includes not listed |
Notifying handlers | Cannot trigger handlers within includes |
Using --start-at-task | Cannot start at tasks within includes |
Using inventory variables | Can include_*: {{ inventory_var }} |
With playbooks | No include_playbook |
With variables files | Can include variables files |
https://docs.ansible.com/ansible/devel/user_guide/playbooks_reuse.html#playbooks-reuse