Ansible Difference between include and import: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=Internal= * <tt>include_tasks</tt>") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Internal= | =Internal= | ||
* [[Ansible_Module_include_tasks#Difference_between_include_tasks_and_import_tasks|< | * [[Ansible_Module_include_tasks#Difference_between_include_tasks_and_import_tasks|include_tasks]] | ||
* [[Ansible_Module_import_tasks#Difference_between_include_tasks_and_import_tasks|import_tasks]] | |||
=Overview= | |||
All <code>import_*</code> statements are pre-processed at the time the playbook is parsed. Import is static. | |||
All <code>include_*</code> statements are processed as they are encountered at runtime during the playbook execution. Include is dynamic. | |||
Import should be used when dealing with logical "units". For example, include a separate long list of tasks into subtask files: | |||
main.yml: | |||
<syntaxhighlight lang='yaml'> | |||
- import_tasks: prepare_filesystem.yml | |||
- import_tasks: install_prerequisites.yml | |||
- import_tasks: install_application.yml | |||
</syntaxhighlight> | |||
Include should be used to deal with different workflows and take decisions based on dynamically gathered facts: | |||
<syntaxhighlight lang='yaml'> | |||
- include_tasks: prerequisites_{{ ansible_os_family | lower }}.yml | |||
</syntaxhighlight> | |||
or | |||
<syntaxhighlight lang='yaml'> | |||
- include_tasks: some-tasks.yml | |||
when: something == "something else" | |||
</syntaxhighlight> |
Latest revision as of 05:21, 7 July 2021
Internal
Overview
All import_*
statements are pre-processed at the time the playbook is parsed. Import is static.
All include_*
statements are processed as they are encountered at runtime during the playbook execution. Include is dynamic.
Import should be used when dealing with logical "units". For example, include a separate long list of tasks into subtask files:
main.yml:
- import_tasks: prepare_filesystem.yml
- import_tasks: install_prerequisites.yml
- import_tasks: install_application.yml
Include should be used to deal with different workflows and take decisions based on dynamically gathered facts:
- include_tasks: prerequisites_{{ ansible_os_family | lower }}.yml
or
- include_tasks: some-tasks.yml
when: something == "something else"