# What's really the purpose of pre\_tasks and post\_tasks?

**URL:** <https://forum.ansible.com/t/whats-really-the-purpose-of-pre-tasks-and-post-tasks/32772>\
**Category:** Ansible Project\
**Created:** [April 23, 2020, 9:05pm UTC](https://forum.ansible.com/t/whats-really-the-purpose-of-pre-tasks-and-post-tasks/32772 "2020-04-23T21:05:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricardo\_Amaral](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Ricardo\_Amaral](https://forum.ansible.com/u/Ricardo_Amaral)\
**Post date:** [April 23, 2020, 9:05pm UTC](https://forum.ansible.com/t/whats-really-the-purpose-of-pre-tasks-and-post-tasks/32772/1 "2020-04-23T21:05:13Z")

</div>

What exactly is the purpose of pre\_tasks/post\_tasks when one can just put "pre" tasks before the main tasks and "post" tasks after the main tasks in the "tasks" directive?

I've read the documentation many times and I can't understand the need for them. I must be missing something here, right?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 23, 2020, 9:07pm UTC](https://forum.ansible.com/t/whats-really-the-purpose-of-pre-tasks-and-post-tasks/32772/2 "2020-04-23T21:07:16Z")

</div>

Primarily they were introduced to provide execution order when using `roles:`. `post_tasks` is probably mostly useless. The execution order is:

pre\_tasks  
roles  
tasks  
post\_tasks

---

<div class="post-metadata">

**Author:** ![Ricardo\_Amaral](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Ricardo\_Amaral](https://forum.ansible.com/u/Ricardo_Amaral)\
**Post date:** [April 23, 2020, 9:10pm UTC](https://forum.ansible.com/t/whats-really-the-purpose-of-pre-tasks-and-post-tasks/32772/3 "2020-04-23T21:10:48Z")

</div>

What exactly is the purpose of roles then? 😅

I mean, is there a difference between roles and use include\_role / import\_role inside tasks?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 23, 2020, 9:15pm UTC](https://forum.ansible.com/t/whats-really-the-purpose-of-pre-tasks-and-post-tasks/32772/4 "2020-04-23T21:15:53Z")

</div>

`roles:` existed long before `include_role` and `import_role`. Many on the core team would say that `import_role` and `include_role` are the future. I personally would like to see `pre_tasks`, `roles`, and `post_tasks` deprecated. Time will tell…

---

<div class="post-metadata">

**Author:** ![Ricardo\_Amaral](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Ricardo\_Amaral](https://forum.ansible.com/u/Ricardo_Amaral)\
**Post date:** [April 23, 2020, 9:22pm UTC](https://forum.ansible.com/t/whats-really-the-purpose-of-pre-tasks-and-post-tasks/32772/5 "2020-04-23T21:22:25Z")

</div>

So, in other words, with include\_role, import\_role, and tasks, one can do pretty much anything that roles, pre\_tasks and post\_tasks can do as well, right?

Thank you so much for your help, that clarifies things for me 🙂

Stay safe!
