Ansible Difference between include and import
Jump to navigation
Jump to search
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"