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
More on Fundamentals and Architecture
What is Ansible and what problem does it solve?BeginnerWhat does "agentless" mean in Ansible?BeginnerWhat are the requirements for the control node?BeginnerWhat does a managed node need?BeginnerIs Ansible push-based or pull-based?BeginnerWalk through what happens when you run `ansible-playbook site.yml`.Intermediate