# How to use a different entry point in the \`roles\` part

**URL:** <https://forum.ansible.com/t/how-to-use-a-different-entry-point-in-the-roles-part/39659>\
**Category:** Get Help\
**Tags:** role\
**Created:** [January 16, 2025, 10:02pm UTC](https://forum.ansible.com/t/how-to-use-a-different-entry-point-in-the-roles-part/39659 "2025-01-16T22:02:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![elrond](https://avatars.discourse-cdn.com/v4/letter/e/5daacb/32.png) [@elrond](https://forum.ansible.com/u/elrond)\
**Post date:** [January 16, 2025, 10:02pm UTC](https://forum.ansible.com/t/how-to-use-a-different-entry-point-in-the-roles-part/39659/1 "2025-01-16T22:02:32Z")

</div>

In some of my roles I would like to use different entry points (not the usual `main.yaml` under tasks, but `other.yaml`).

The relatively new Role argument validation (see the start of the [specs](https://docs.ansible.com/ansible/devel/playbook_guide/playbooks_reuse_roles.html#specification-format)) has primary support for entry points.

For `include_role` / `import_role` this is well supported using the `tasks_from` keyword.

But for the “old” `roles:` part in a play, it doesn’t seem to be supported. At least, according to this stackoverflow post:

> <https://stackoverflow.com/questions/71513779/how-to-use-a-different-entry-point-in-ansible-roles>

Why is it not supported for the `roles:` part?

- Am I just missing the proper documentation on how to call it with an entry point? Then maybe someone please go ahead and post a new answer on that stackoverflow posting. Please.
- Is this considered so advanced, that you’re anyway expected to use `include_role` / `import_role`?
- Is the `roles:` part heading towards a deprecation?

Just wondering…

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [January 17, 2025, 1:50pm UTC](https://forum.ansible.com/t/how-to-use-a-different-entry-point-in-the-roles-part/39659/2 "2025-01-17T13:50:02Z")

</div>

I don’t know if there is official documentation concerning this, but when I started using Ansible several years ago, multiple people on IRC told me not to use the `roles:` , as it was the “old” way to do it and would be deprecated…instead to use `include_role` / `import_role`, which were far more advanced and the future standard.

So I have never used `roles:` myself, and don’t believe there is any benefit to it…

---

<div class="post-metadata">

**Author:** ![elrond](https://avatars.discourse-cdn.com/v4/letter/e/5daacb/32.png) [@elrond](https://forum.ansible.com/u/elrond)\
**Post date:** [January 17, 2025, 5:28pm UTC](https://forum.ansible.com/t/how-to-use-a-different-entry-point-in-the-roles-part/39659/3 "2025-01-17T17:28:00Z")

</div>

> [@jrglynn2](#):
>
> I don’t know if there is official documentation concerning this, but when I started using Ansible several years ago, multiple people on IRC told me not to use the `roles:` , as it was the “old” way to do it and would be deprecated…

I have found this old thread that also suggests this: ["import\_role" vs "roles"](https://forum.ansible.com/t/import-role-vs-roles/28734)

IMHO it would really be helpful, if there was some more information on possible deprecation plans.

> [@jrglynn2](#):
>
> So I have never used `roles:` myself, and don’t believe there is any benefit to it…

Benefit… depends on the view. If you have a few simple roles, then

```yaml
roles:
- role1
- role2
- role3

```

is quite concise. Doing the same in the new syntax is something like this:

```yaml
tasks:
- ansible.builtin.import_role:
    name: role1
- ansible.builtin.import_role:
    name: role2

```

which feels quite verbose.

Yes, you could use `include_role` and `loop:`. But `include_role` has different semantics than `import_role` (which is closer to `roles:`).

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [January 17, 2025, 5:44pm UTC](https://forum.ansible.com/t/how-to-use-a-different-entry-point-in-the-roles-part/39659/4 "2025-01-17T17:44:41Z")

</div>

> [@jrglynn2](#):
>
> people on IRC told me not to use the `roles:` , as it was the “old” way to do it and would be deprecated

Don’t believe random people on the internet (including me). While i WISH this were true, `roles:` is not deprecated and is not going anywhere, but it is also not going to get new features as the way it works is very different from what we can do with `include_role`/`import_role`.

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [January 17, 2025, 5:53pm UTC](https://forum.ansible.com/t/how-to-use-a-different-entry-point-in-the-roles-part/39659/5 "2025-01-17T17:53:26Z")

</div>

> [@elrond](#):
>
> which feels quite verbose.

Ehh, I guess it’s a matter of taste. I would rather have it be “verbose” myself - easier to remember things months/years later when you/others are reviewing code 🙂

> [@bcoca](#):
>
> , `roles:` is not deprecated and is not going anywhere, but it is also not going to get new features as the way it works is very different from what we can do with `include_role`/`import_role`.

Good note, thanks. I find include/import role to work great for what I need.

---

<div class="post-metadata">

**Author:** ![elrond](https://avatars.discourse-cdn.com/v4/letter/e/5daacb/32.png) [@elrond](https://forum.ansible.com/u/elrond)\
**Post date:** [January 19, 2025, 5:20pm UTC](https://forum.ansible.com/t/how-to-use-a-different-entry-point-in-the-roles-part/39659/6 "2025-01-19T17:20:13Z")

</div>

> [@bcoca](#):
>
> […] `roles:` is not deprecated and is not going anywhere, but it is also not going to get new features as the way it works is very different from what we can do with `include_role`/`import_role`.

Is there any documentation on this?

For example the [Using roles at the play level](https://docs.ansible.com/ansible/devel/playbook_guide/playbooks_reuse_roles.html#using-roles-at-the-play-level) docs do not mention that using include/import-role is rather recommended except for the “The classic (original) way to use roles” at the beginning.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [January 20, 2025, 3:36pm UTC](https://forum.ansible.com/t/how-to-use-a-different-entry-point-in-the-roles-part/39659/7 "2025-01-20T15:36:53Z")

</div>

There is no official recommendation of one over the other, the point is that they work differently and are not expected to have the same features, if they were all the same, only one would exist.

My personal recommendation is to avoid roles/pre\_tasks/post\_tasks as I (me, myself and no one else) feel that they add unneeded complexity to plays.

There is only one case I can find for pre\_tasks and there is still a better workaround, executing something before gathering. But you can also:

```auto
gather_facts: false
tasks:
 - dostuff:

- gather_facts: 
  when: ansible_facts.get('module_setup', False)

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 19, 2025, 3:36pm UTC](https://forum.ansible.com/t/how-to-use-a-different-entry-point-in-the-roles-part/39659/8 "2025-02-19T15:36:54Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
