"import_role" vs "roles"

Hi, I would like to clarify things relating to new “import_role” statement - documentation mentions it as a “new syntax” however it does not mention about the plans for the “roles” syntax. What’s the plan moving forward. I see both statements as distinct entities, however some of my colleagues seem to be confused about the state of affairs so we’d like some clarification on the matter.

So, to re-phrase my question differently:

is there a merit in abandoning “roles:” statement from our playbooks moving forward in favor of “import_role” to future-proof our code?

In my experience, I’ve really only used import_role as a task-level declaration, Occasionally after some preliminary setup tasks.

The roles declaration at the top of the playbook will always execute before the set of tasks in a given playbook.

It’s possible there are other, potentially larger, facets that I’m missing but for the most part the only significant distinctions I’ve been able to make between the two of them is ordering, specifically that:

  • roles declared in the roles heading will be executed before all tasks in a playbook

  • tasks that use the import_role module(?) are able to be arranged wherever the playbook writer chooses in the task list, giving a lot more flexibility on the side of playbook designers.

Hope this helps!

It's a little more refined since you have pre_tasks, tasks and post_tasks and the execution order is pre_tasks, roles, tasks and post_tasks.

Additional question: Can "import_role: " or "include_role: ", accept a list of roles? Examples appear to only have one role. "Roles: " examples usually show a list of one or more roles.

No, if it could it would be documented under the name parameter in the documentation.

You can use loops but there are differences about how they work on import vs include, but this behavior is documented under Synopsis under the respective modules.