# Best way to add reusable provisioning steps to existing roles

**URL:** <https://forum.ansible.com/t/best-way-to-add-reusable-provisioning-steps-to-existing-roles/15736>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [July 22, 2014, 8:32pm UTC](https://forum.ansible.com/t/best-way-to-add-reusable-provisioning-steps-to-existing-roles/15736 "2014-07-22T20:32:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![itarchmerc](https://avatars.discourse-cdn.com/v4/letter/i/ecb155/32.png) [@itarchmerc](https://forum.ansible.com/u/itarchmerc)\
**Post date:** [July 22, 2014, 8:32pm UTC](https://forum.ansible.com/t/best-way-to-add-reusable-provisioning-steps-to-existing-roles/15736/1 "2014-07-22T20:32:33Z")

</div>

What would be the best method to add reusable provisioning steps to existing roles? I am looking to try and accomplish the following:

- Ideally this could be it’s own role, or in some way reusable so I could tie it to any role
- It would pull in all the needed parameters from group or host vars
- It would only be called if I sent something like ansible-playbook -e “provision=yes”, otherwise the role would run as written without provisioning an instance
- I would like a way to easily extend this for additional providers (e.g. EC2, VMWare, GCE, etc)  
I have been able to add provisioning steps into an existing role by using a separate task, but I feel like there is a better and more reusable way to approach this. Please let me know if additional clarification is needed. Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [July 22, 2014, 9:36pm UTC](https://forum.ansible.com/t/best-way-to-add-reusable-provisioning-steps-to-existing-roles/15736/2 "2014-07-22T21:36:52Z")

</div>

I actually tackle this another way. I write provisioning playbooks  
(not a role) that will create the server on the provider. And then  
when it's finished, run some bootstrapping steps. After that is done,  
use add\_host to add it to the right group and then include the  
role-level playbook.

This way the roles don't need to know anything about provisioning. The  
step to provision new servers is a different command and as soon as a  
server is provisioned it's handed off to the appropriate roles to get  
it configured. And because our inventory is dynamic the new server  
will be included in subsequent runs too.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 23, 2014, 1:26pm UTC](https://forum.ansible.com/t/best-way-to-add-reusable-provisioning-steps-to-existing-roles/15736/3 "2014-07-23T13:26:40Z")

</div>

Yep, use roles to describe the states and behaviors, and include those roles in multiple playbooks as appropriate.

If you have a configure.yml as a playbook, the “provision.yml” could just include it as the very last line of the playbook, making it easy to run things together using the “add\_hosts” trick as described in (for example) the EC2 guide.

[http://docs.ansible.com/guide\_aws.html](http://docs.ansible.com/guide_aws.html)

---

<div class="post-metadata">

**Author:** ![itarchmerc](https://avatars.discourse-cdn.com/v4/letter/i/ecb155/32.png) [@itarchmerc](https://forum.ansible.com/u/itarchmerc)\
**Post date:** [July 23, 2014, 3:38pm UTC](https://forum.ansible.com/t/best-way-to-add-reusable-provisioning-steps-to-existing-roles/15736/4 "2014-07-23T15:38:24Z")

</div>

Thank you for the suggestions. I have implemented and tested them and it’s all working great.
