# Re-using a pre\_task and post\_task using roles?

**URL:** <https://forum.ansible.com/t/re-using-a-pre-task-and-post-task-using-roles/17733>\
**Category:** Ansible Project\
**Created:** [March 12, 2015, 8:07pm UTC](https://forum.ansible.com/t/re-using-a-pre-task-and-post-task-using-roles/17733 "2015-03-12T20:07:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_S](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sam\_S](https://forum.ansible.com/u/Sam_S)\
**Post date:** [March 12, 2015, 8:07pm UTC](https://forum.ansible.com/t/re-using-a-pre-task-and-post-task-using-roles/17733/1 "2015-03-12T20:07:37Z")

</div>

Let’s say I need to deploy two sets of applications - PHP vs PERL.

I want to be able to re-use the pre\_tasks and post\_tasks snippet so that i dont have to make changes to multiple scripts if I modify a value for the netscaler module. I guess my question is what’s the point of using “pre\_tasks” and “post\_tasks” if I can put them inside a role as dependencies?

See below for original script. I would essentially do the same thing for my perl deploys. I would like to throw the “pre\_tasks” and “post\_tasks” into one file and call them when I need to. What’s the best way to handle that?

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [March 13, 2015, 7:45am UTC](https://forum.ansible.com/t/re-using-a-pre-task-and-post-task-using-roles/17733/2 "2015-03-13T07:45:42Z")

</div>

You can create additional lb/disable\_host and lb/enable\_host roles.  
You can also try parameterizing the deploy role name and then using playbook-level includes, but I’m not sure if that’ll work

Samnang Sen [samnang.sen@gmail.com](mailto:samnang.sen@gmail.com) napisał:
