# Question about organizing roles and playbooks

**URL:** <https://forum.ansible.com/t/question-about-organizing-roles-and-playbooks/22892>\
**Category:** Ansible Project\
**Created:** [October 26, 2016, 3:28pm UTC](https://forum.ansible.com/t/question-about-organizing-roles-and-playbooks/22892 "2016-10-26T15:28:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thokari81](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@thokari81](https://forum.ansible.com/u/thokari81)\
**Post date:** [October 26, 2016, 3:28pm UTC](https://forum.ansible.com/t/question-about-organizing-roles-and-playbooks/22892/1 "2016-10-26T15:28:45Z")

</div>

Hello,  
How to best model the following scenario:

I have a set of hosts in one playbook.

[qa-machines]  
HostA  
HostB  
HostC

I have a subset of these hosts that should receive additional roles.

[jenkins-slaves]  
HostC

I have a Vagrantfile that I would like to use to set up one host of each category.

Including first playbook from the second one does not work, because I cannot parameterize the hosts when including a playbook.

What I would like to achieve is, when the “setup-qa-machine” playbook is changed, it does not require to change in the “setup-jenkins-slave” playbook, which would be the case if I repeated the common roles.

it feels a bit like I was not seeing the obvious right now, so any help is appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![rup](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@rup](https://forum.ansible.com/u/rup)\
**Post date:** [October 26, 2016, 5:21pm UTC](https://forum.ansible.com/t/question-about-organizing-roles-and-playbooks/22892/2 "2016-10-26T17:21:02Z")

</div>

We implemented this by having host files specific to an environment, so for example, a QA host file, a Prod host file, a Dev host file, etc. Then the groupings within the host file would be based off what they were used for, for example:

[wildfly\_servers]  
HostA  
HostB

[activemq\_servers]  
HostB

[db\_servers]  
HostA

[akka\_servers]  
HostB

[php\_servers]  
HostA

[php\_innovations\_servers]  
HostA

Then when calling the playbook, we just pull in the appropriate host file for the environment we want to have updated. Is this what you were talking about?

---

<div class="post-metadata">

**Author:** ![Dan\_Rough](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dan\_Rough](https://forum.ansible.com/u/Dan_Rough)\
**Post date:** [October 26, 2016, 8:46pm UTC](https://forum.ansible.com/t/question-about-organizing-roles-and-playbooks/22892/3 "2016-10-26T20:46:47Z")

</div>

If I understand your question correctly, then why not just have two playbooks? We have an infrastructure.yml playbook which provisions a server for us. We also have another playbook which makes alterations to that server dependent on its role. For example, in our case when we provision a Jenkins server, I run the infrastructure.yml playbook which targets all servers (qa-machines in your case) in its host specification (remember that you can use [ansible’s limit](http://docs.ansible.com/ansible/playbooks_best_practices.html#top-level-playbooks-are-separated-by-role) attribute to narrow the scope of the playbook from the command line) and then I run jenkins.yml afterwards which targets just the jenkins server (jenkins-slaves in your example).

---

<div class="post-metadata">

**Author:** ![thokari81](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@thokari81](https://forum.ansible.com/u/thokari81)\
**Post date:** [October 27, 2016, 9:54am UTC](https://forum.ansible.com/t/question-about-organizing-roles-and-playbooks/22892/4 "2016-10-27T09:54:26Z")

</div>

Not exactly, however I realize that by “double-assigning” hosts in my inventory I have kind of solved my problem already. The issue is that my “second” hosts file / inventory is currently generated by Vagrant, so I need to create the appropriate groups there, also.  
Like i suspected the problem lies more with my use of Vagrant, rather than Ansible.

Thanks for your comment!

---

<div class="post-metadata">

**Author:** ![thokari81](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@thokari81](https://forum.ansible.com/u/thokari81)\
**Post date:** [October 27, 2016, 9:57am UTC](https://forum.ansible.com/t/question-about-organizing-roles-and-playbooks/22892/5 "2016-10-27T09:57:55Z")

</div>

This is exactly what I am doing, except I need this to happen also when using Vagrant by assigning groups properly when I have the inventory generated by it (see above comment).  
I am still deliberating if I should maintain the second inventory directly, or have it generated…  
Thanks for your help, much appreciated!
