Interview Prep/Ansible/Roles, Collections and Galaxy

A task under `tasks:` installs a prerequisite, but the role that needs it fails first

BeginnerTroubleshootingRoles, Collections and Galaxy
Answer

Likely causes → Play order is fixed: pre_tasks → their handlers → roles → tasks → their handlers → post_tasks. Everything in roles: runs before tasks:, whatever order the file is written in.

Fix → Move the prerequisite to pre_tasks, or place the role exactly where you need it with import_role inside tasks:.

Prevent → In a play, use either roles: or tasks: with import_role, not both, so the order you read is the order that runs.

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Galaxy