# breaking up complex playbook into pieces

**URL:** <https://forum.ansible.com/t/breaking-up-complex-playbook-into-pieces/15544>\
**Category:** Ansible Project\
**Created:** [June 25, 2014, 5:02pm UTC](https://forum.ansible.com/t/breaking-up-complex-playbook-into-pieces/15544 "2014-06-25T17:02:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [June 25, 2014, 5:02pm UTC](https://forum.ansible.com/t/breaking-up-complex-playbook-into-pieces/15544/1 "2014-06-25T17:02:39Z")

</div>

Hi,

I’ve got my playbook large enough now that whenever I want to execute only bits of it I either have to code-in lots of conditionals and “special” variables or do some other trickery. I’ve got things split out into roles, so that my main file site.yml looks like:

- hosts: all  
roles:

- role: commonAll

- role: collect\_facts

- hosts: groupA  
roles:

- role: common1

- role: roleA

- hosts: groupB  
roles:

- role: common2

- role: roleB

…

now I would like to break this into bunch of smaller files and be able to execute them per-role/per-group. Thing is sometimes I have the same host in multiple groups (and subsequently in several roles) and executing with just “–limit” hooks into groups/roles I don’t want to. So I created bunch of files like:

…common.yml…

- hosts: all  
roles:
- role: commonAll
- role: collect\_facts  
…

…fileA.yml…

- hosts: groupA

roles:

- role: common1
- role: roleA

…  
…fileB.yml…

- hosts: groupB

roles:

- role: commonB
- role: roleB

…

…groupB.yml…

- include common.yml
- include fileB.yml  
…

and master site.yml to look like:

- include common.yml
- include fileA.yml
- include fileB.yml  
…

so that I can either launch site.yml or any of the groups separately: groupX.yml . Now from all of the above, I get ridiculous number of files at the top level. Trying to move fileX.yml into subdirectory services results in ansible inability to locate roles definitions.

Now the actual question: what are the best practices in cases like the one I’ve described? One thing I can think of is to restructure everything introducing one more directory layer, so instead of book/roles/foo I’ll get top/book/roles/foo and move all of the fileX.yml under top/ and have groupX and site.yml files at the very top level. Is that how others are addressing such problems?

---

<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:** [June 26, 2014, 12:12am UTC](https://forum.ansible.com/t/breaking-up-complex-playbook-into-pieces/15544/2 "2014-06-26T00:12:38Z")

</div>

having a site.yml that includes a webservers.yml and a dbservers.yml is in fact a reasonable thing to do if you want a quick shorthand to just run a part of your infrastructure through Ansible.

---

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [June 26, 2014, 10:10pm UTC](https://forum.ansible.com/t/breaking-up-complex-playbook-into-pieces/15544/3 "2014-06-26T22:10:31Z")

</div>

how do I get around the issue of roles being relative to playbook file and not CWD ?

---

<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:** [June 27, 2014, 12:45pm UTC](https://forum.ansible.com/t/breaking-up-complex-playbook-into-pieces/15544/4 "2014-06-27T12:45:23Z")

</div>

I’m not sure why it’s an issue, but I’m having difficulty following.

Please also note roles\_path is configurable in ansible.cfg if this is useful to you.
