# Feature Request: pre\_tasks and post\_tasks for each role.

**URL:** <https://forum.ansible.com/t/feature-request-pre-tasks-and-post-tasks-for-each-role/13319>\
**Category:** Ansible Project\
**Created:** [August 16, 2013, 12:46pm UTC](https://forum.ansible.com/t/feature-request-pre-tasks-and-post-tasks-for-each-role/13319 "2013-08-16T12:46:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Smoothify](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@Smoothify](https://forum.ansible.com/u/Smoothify)\
**Post date:** [August 16, 2013, 12:46pm UTC](https://forum.ansible.com/t/feature-request-pre-tasks-and-post-tasks-for-each-role/13319/1 "2013-08-16T12:46:57Z")

</div>

I want to have two or more task stages for roles, one for initialization and one for installation / configuration.

My initial thoughts were to use the pre\_task and post\_tasks for each role, though I realise they were intended for load balancing.

Here is an example usage:

roles/mariadb/pre\_tasks/main.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 16, 2013, 6:01pm UTC](https://forum.ansible.com/t/feature-request-pre-tasks-and-post-tasks-for-each-role/13319/2 "2013-08-16T18:01:54Z")

</div>

Ok, so looking at the above I’m thinking you don’t need pre\_tasks and post\_tasks for this.

What you should do is have a role that sets up your keys/repos, call it “repos”, OR just prefix your repo setup before your tasks for installation.

You could then make a role named “update packages” and put it at the end if you want.

roles:

- repo\_setup # optional
- mariadb
- update\_all

Would that work? I’d probably just set up the repos in the mariadb role if it were me, but I would probably use tasks includes to break things up into multiple files  
if the tasks got too long.

---

<div class="post-metadata">

**Author:** ![Smoothify](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@Smoothify](https://forum.ansible.com/u/Smoothify)\
**Post date:** [August 20, 2013, 12:57pm UTC](https://forum.ansible.com/t/feature-request-pre-tasks-and-post-tasks-for-each-role/13319/3 "2013-08-20T12:57:31Z")

</div>

Thanks for looking at this.

Yes, there are other ways i could achieve this - either through additional roles or just by taking the performance penalty of updating the repo database for each role.

I did like the cleanliness of keeping everything related to a role inside its own folder, as i’m looking to open source the role files, so would probably go for the latter.

Would you consider a patch for adding these stages, or are you opposed to the idea ?
