# Structure of role-base configuration of hosts

**URL:** <https://forum.ansible.com/t/structure-of-role-base-configuration-of-hosts/11472>\
**Category:** Ansible Project\
**Created:** [April 30, 2012, 5:54pm UTC](https://forum.ansible.com/t/structure-of-role-base-configuration-of-hosts/11472 "2012-04-30T17:54:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@Frank](https://forum.ansible.com/u/Frank)\
**Post date:** [April 30, 2012, 5:54pm UTC](https://forum.ansible.com/t/structure-of-role-base-configuration-of-hosts/11472/1 "2012-04-30T17:54:15Z")

</div>

Hi,

I really like the idea of role-base configuration of hosts. What do I  
mean with this? A role means to me e.g. "database-server", "app-  
server", "web-server". Depending on the environment (test or  
production) I would like to assign these roles to hosts in a different  
way:

Production environment with 4 separate hosts:  
&nbsp;&nbsp;prod-db-host role(s): database-server  
&nbsp;&nbsp;prod-app1 role(s): app-server,  
&nbsp;&nbsp;prod-app2 role(s): app-server,  
&nbsp;&nbsp;prod-web-server role(s): web-server

Frank's test environment with just 1 host that is doing everything:  
&nbsp;&nbsp;test-frank-host role(s): database-server+app-server+web-server

Now I write how I try to implement this with Ansible. I would like to  
get some feedback whether there are better ways to do this.

I configure playbooks for each role, i.e. I create a "database-  
server.yml", "app-server.yml", "web-server.yml". These playbooks also  
include some things like e.g. handlers. Each of this playbook is  
restricted to only one role, i.e. the "database-server.yml" starts  
with

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 30, 2012, 6:13pm UTC](https://forum.ansible.com/t/structure-of-role-base-configuration-of-hosts/11472/2 "2012-04-30T18:13:58Z")

</div>

> Hi,
> 
> I really like the idea of role-base configuration of hosts.

Groups are usable for this.

Have a play for each group.

> I also would like to put all together playbooks together to simply the  
> execution, i.e. I would like to create a “all.yml” that includes  
> database-server.yml", “app-server.yml”, “web-server.yml” (to simplify  
> the execution and to have all stuff in my version control system):  
> ansible-playbook all.yml --debug --inventory=prod-hosts

Just have a top level play with multiple plays for each group

The first play targets web servers and runs webserver.yml, the next targets database servers and runs dbserver.yml, etc

> Unfortunately, this is impossible because nested includes are not  
> allowed.

It’s totally possible, see above.

---

<div class="post-metadata">

**Author:** ![Frank](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@Frank](https://forum.ansible.com/u/Frank)\
**Post date:** [April 30, 2012, 6:22pm UTC](https://forum.ansible.com/t/structure-of-role-base-configuration-of-hosts/11472/3 "2012-04-30T18:22:12Z")

</div>

Hi Michael,

> Have a play for each group.

but this means that all configuration is in one big/huge file. Do you  
think, this is a good idea?

Frank

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 30, 2012, 6:43pm UTC](https://forum.ansible.com/t/structure-of-role-base-configuration-of-hosts/11472/4 "2012-04-30T18:43:10Z")

</div>

I don’t think it would be very large if you had a sane number of groups.

Generally the play is intended to define a role, and the actual group name is just grouping some machines together.

Groups are not necessarily roles and may often be geographic.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 30, 2012, 7:04pm UTC](https://forum.ansible.com/t/structure-of-role-base-configuration-of-hosts/11472/5 "2012-04-30T19:04:32Z")

</div>

Here is an example of a top level playbook where include files are used to map roles to hosts:

[https://github.com/mpdehaan/ansible-examples/blob/master/monitoring.yml](https://github.com/mpdehaan/ansible-examples/blob/master/monitoring.yml)

Assume it was named “site.yml” instead of “monitoring.yml”, if you like.
