# Best way to organize your playbooks

**URL:** <https://forum.ansible.com/t/best-way-to-organize-your-playbooks/30928>\
**Category:** Ansible Project\
**Created:** [August 1, 2019, 5:31am UTC](https://forum.ansible.com/t/best-way-to-organize-your-playbooks/30928 "2019-08-01T05:31:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![user89](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@user89](https://forum.ansible.com/u/user89)\
**Post date:** [August 1, 2019, 5:31am UTC](https://forum.ansible.com/t/best-way-to-organize-your-playbooks/30928/1 "2019-08-01T05:31:49Z")

</div>

I have a several projects which describing installation 2 different applications. Each directory for application:

app1/roles/common/main.yml  
app2/roles/common/main.yml

But application have similar between them tasks which described in “main.yml” of role “common”

What is the best way have only one source to those similar tasks without having 2 or more versions and duplicate them across projects. From my point of view:

It can be separate dir:  
playbooks/common\_tasks.yml

Which will be imported to those “main.yml” files:

app1/roles/common/main.yml  
app2/roles/common/main.yml

But maybe someone else see a better solution?

---

<div class="post-metadata">

**Author:** ![Sebastian\_Meyer](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@Sebastian\_Meyer](https://forum.ansible.com/u/Sebastian_Meyer)\
**Post date:** [August 1, 2019, 5:44am UTC](https://forum.ansible.com/t/best-way-to-organize-your-playbooks/30928/2 "2019-08-01T05:44:16Z")

</div>

You could make use of the roles\_path configuration setting [0] and have  
a directory structure like this:

ansible/  
&nbsp;&nbsp;common/roles/  
&nbsp;&nbsp;app1/roles/  
&nbsp;&nbsp;app2/roles/

and in the app folders each an ansible.cfg with:

roles\_path: ./roles:../common/roles

[0]  
[https://docs.ansible.com/ansible/latest/reference\_appendices/config.html#default-roles-path](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-roles-path)

---

<div class="post-metadata">

**Author:** ![user89](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@user89](https://forum.ansible.com/u/user89)\
**Post date:** [August 1, 2019, 5:49am UTC](https://forum.ansible.com/t/best-way-to-organize-your-playbooks/30928/3 "2019-08-01T05:49:52Z")

</div>

Awesome! Looks like a plan! Thanks!

чт, 1 авг. 2019 г. в 07:44, Sebastian Meyer \<[meyer@b1-systems.de](mailto:meyer@b1-systems.de)\>:

---

<div class="post-metadata">

**Author:** ![Andrew\_Feller](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Andrew\_Feller](https://forum.ansible.com/u/Andrew_Feller)\
**Post date:** [August 1, 2019, 9:51am UTC](https://forum.ansible.com/t/best-way-to-organize-your-playbooks/30928/4 "2019-08-01T09:51:36Z")

</div>

You might re-examine whether it is appropriate for a role and a playbook as it feels like your playbooks are too heavy.

Roles ideally should be reusable logic for a given context you can apply to multiple situations. For example, you might have multiple kafka/mysql/etc clusters for different uses that a single role given the necessary info via playbook and inventory can manage. If you need to build higher order reusable roles, you can have roles with dependent roles that compose them to your ends; leaving your playbooks thinner. Playbooks ultimately should be highest order orchestration that isn’t bogged down into all of the technical details.

Say what you will about Puppet but I would consider the reasoning behind their roles and profiles and how it applies to Ansible: [https://puppet.com/docs/pe/2018.1/the\_roles\_and\_profiles\_method.html](https://puppet.com/docs/pe/2018.1/the_roles_and_profiles_method.html)

---

<div class="post-metadata">

**Author:** ![user89](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@user89](https://forum.ansible.com/u/user89)\
**Post date:** [August 1, 2019, 1:36pm UTC](https://forum.ansible.com/t/best-way-to-organize-your-playbooks/30928/5 "2019-08-01T13:36:57Z")

</div>

Think re-examine how i look into the roles is helped to me. Now after i reorganize my roles slightly different is helped for me:

Each role have purpose of install nginx, monitoring, etc.

And after that high level playbook will combine them together to get application worked. For example distributed wordpress, or ha lamp stack rather than I have before each role to configure application.
