In an Ansible playbook, roles are processed before the ansible.builtin.import_role
task.
Roles are a collection of tasks, handlers, templates, files, and other resources grouped together to perform a specific function. When a role is included in a playbook, Ansible first processes the role’s tasks and handlers before continuing with the rest of the playbook’s tasks.
The ansible.builtin.import_role
task is a built-in task that allows you to import and run a role within a playbook. When this task is executed, Ansible processes the role’s tasks and handlers before continuing with the rest of the playbook’s tasks.
Therefore, if you use the ansible.builtin.import_role
task to import a role in a playbook, the role’s tasks and handlers will be processed before the tasks in the playbook that come after the ansible.builtin.import_role
task.
Here is an example playbook that uses the ansible.builtin.import_role
task to import a role:
- hosts: all
tasks:
- name: Import role
ansible.builtin.import_role:
name: myrole
- name: Run tasks after role
debug:
msg: "Tasks after role"
In this example, the myrole
role will be processed before the Run tasks after role
task.