"import_role" vs "roles"

68 views
Skip to first unread message

Dmitry Makovey

unread,
Oct 5, 2018, 4:30:08 PM10/5/18
to Ansible Project
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?

Will Weber

unread,
Oct 5, 2018, 10:37:32 PM10/5/18
to ansible...@googlegroups.com
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!

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e17de5ec-7f17-4933-9615-b8c169bd6645%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Oct 6, 2018, 2:56:25 AM10/6/18
to ansible...@googlegroups.com
On 06.10.2018 04:36, Will Weber wrote:
> 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

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.

--
Kai Stian Olstad

Trammael

unread,
Jan 13, 2019, 2:41:54 PM1/13/19
to Ansible Project
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.

Kai Stian Olstad

unread,
Jan 13, 2019, 2:52:40 PM1/13/19
to ansible...@googlegroups.com
On Sunday, 13 January 2019 20:41:53 CET Trammael wrote:
>
> 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.


--
Kai Stian Olstad


Reply all
Reply to author
Forward
0 new messages