There’s quite a bit about this topic in the documentation:
The main difference is:
All
import*statements are pre-processed at the time playbooks are parsed.
Allinclude*statements are processed as they encountered during the execution of the playbook.
So import is static, include is dynamic.
From my experience, you should use import when you deal with logical “units”. For example, 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
But you would use include to deal with different workflows and take decisions based on some dynamically gathered facts:
install_prerequisites:
- include_tasks: prerequisites_{{ ansible_os_family | lower }}.yml