In an Ansible playbook, roles are processed before the
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.
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
Here is an example playbook that uses the
ansible.builtin.import_role task to import a role:
- hosts: all
- name: Import role
- name: Run tasks after role
msg: "Tasks after role"
In this example, the
myrole role will be processed before the
Run tasks after role task.