# Tasks play-level vs. role-level

**URL:** <https://forum.ansible.com/t/tasks-play-level-vs-role-level/30707>\
**Category:** Ansible Project\
**Created:** [July 3, 2019, 3:56pm UTC](https://forum.ansible.com/t/tasks-play-level-vs-role-level/30707 "2019-07-03T15:56:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kdt](https://avatars.discourse-cdn.com/v4/letter/k/85f322/32.png) [@kdt](https://forum.ansible.com/u/kdt)\
**Post date:** [July 3, 2019, 3:56pm UTC](https://forum.ansible.com/t/tasks-play-level-vs-role-level/30707/1 "2019-07-03T15:56:52Z")

</div>

Task in some play imports or includes role (for the project here roles used in playbook are grabbed from external repositories, not in one repo along with playbook).  
Within role each item starting with “-name:” line is also called “a task” - as I guess.  
Please compare with [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_reuse\_roles.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html) section “Using Roles” and roles/example/tasks/main.yml in section “Role Directory Structure”.

So the structure looks like task (play-level) \> sub-task (each entry starting with "name: "-line in role). Is this the proper understanding?  
Does it eventually work in other way: if task was open at play level one does not must open a task in role imported/included from that play, and vice-versa?

---

<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:** [July 16, 2019, 1:04pm UTC](https://forum.ansible.com/t/tasks-play-level-vs-role-level/30707/2 "2019-07-16T13:04:04Z")

</div>

`name` is an optional keyword in a task the `-` and the actual action  
are the 'important parts', be it in a role or directly in a play does  
not change the nature of a task.

---

<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:** [July 18, 2019, 1:44pm UTC](https://forum.ansible.com/t/tasks-play-level-vs-role-level/30707/3 "2019-07-18T13:44:34Z")

</div>

This is a draft still, but an attempt to clarify this in simplest  
terms possible [https://github.com/ansible/ansible/pull/59163](https://github.com/ansible/ansible/pull/59163)

---

<div class="post-metadata">

**Author:** ![kdt](https://avatars.discourse-cdn.com/v4/letter/k/85f322/32.png) [@kdt](https://forum.ansible.com/u/kdt)\
**Post date:** [July 19, 2019, 8:47am UTC](https://forum.ansible.com/t/tasks-play-level-vs-role-level/30707/4 "2019-07-19T08:47:47Z")

</div>

Thanks for the link.  
Pretty helpful manual.

By which term can one refer to every item in role file starting with “- name: ” or with “\<module\_name\>:” ?  
By which term can one refer to every item in playbook file starting with “- name: ” or with “import\_role:”?

---

<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:** [July 23, 2019, 6:29pm UTC](https://forum.ansible.com/t/tasks-play-level-vs-role-level/30707/5 "2019-07-23T18:29:35Z")

</div>

> By which term can one refer to every item in role file starting with "- name: \<task name\>" or with "\<module\_name\>:" ?

depends on teh file, but it looks like you mean tasks/main.yml, those  
are 'tasks'

> By which term can one refer to every item in playbook file starting with "- name: \<task name\>" or with "import\_role:"?

import\_role is an action of a task, not everything in a playbook that  
starts with "-" is a task, tasks must be inside plays, anything 'top  
level' of a playbook is a play

---

<div class="post-metadata">

**Author:** ![kdt](https://avatars.discourse-cdn.com/v4/letter/k/85f322/32.png) [@kdt](https://forum.ansible.com/u/kdt)\
**Post date:** [July 24, 2019, 8:25am UTC](https://forum.ansible.com/t/tasks-play-level-vs-role-level/30707/6 "2019-07-24T08:25:17Z")

</div>

Hi,  
Thank you for input from you.

Yes, I missed to make update of my question precising these points. Sorry for that.

Yes, if it concerns role files I mean “- name: ” or with “\<module\_name\>:” -lines in tasks/main.yml

If it concerns playbook files I mean “- name: ” or with “import\_role:” items conducting the import of a role, latter one addressed in the point above.  
You claim import\_role is an action of a task. So in end-effect task at playbook-level is including another tasks provided by role. How to differentiate in discussions between these two tasks? parent and child tasks? In any other way?

---

<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:** [July 25, 2019, 2:00pm UTC](https://forum.ansible.com/t/tasks-play-level-vs-role-level/30707/7 "2019-07-25T14:00:43Z")

</div>

include\_tasks/import\_tasks/include\_role/import\_role all capable of  
expanding the task list via other files, not sure what you mean by  
parent/child .. there is really not that concept at task level.

why would you need to know?

---

<div class="post-metadata">

**Author:** ![kdt](https://avatars.discourse-cdn.com/v4/letter/k/85f322/32.png) [@kdt](https://forum.ansible.com/u/kdt)\
**Post date:** [July 25, 2019, 3:22pm UTC](https://forum.ansible.com/t/tasks-play-level-vs-role-level/30707/8 "2019-07-25T15:22:10Z")

</div>

Role defines a tasks. It does it at the point where in play an entry (which appears to be a task) imports that role \> in end-effect a task within another task,  
or how to understand this
