Interview Prep/Ansible/Fundamentals and Architecture

What is the difference between parse-time (static) and run-time (dynamic) processing?

AdvancedConceptFundamentals and Architecture
Answer

import_* statements (import_tasks, import_role, import_playbook) are static: Ansible expands them when the playbook is parsed, so tags, when and --list-tasks see every task. include_* statements (include_tasks, include_role) are dynamic: they are evaluated at run time, when the task is reached.

Consequences: variables defined at run time (loops, set_fact, registered results) can drive include_tasks but not import_tasks file names; --list-tasks and tags on an include_tasks do not apply to the included tasks unless you use apply; and a when on an import_tasks is copied to every imported task rather than evaluated once.

- ansible.builtin.include_tasks: "{{ ansible_os_family | lower }}.yml"   # dynamic, OK
- ansible.builtin.import_tasks: common.yml                              # static
All Ansible questions Roadmap: Ansible

More on Fundamentals and Architecture