# Inventory with more than one server per host

**URL:** <https://forum.ansible.com/t/inventory-with-more-than-one-server-per-host/16888>\
**Category:** Ansible Project\
**Created:** [November 26, 2014, 6:57am UTC](https://forum.ansible.com/t/inventory-with-more-than-one-server-per-host/16888 "2014-11-26T06:57:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronny](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@Ronny](https://forum.ansible.com/u/Ronny)\
**Post date:** [November 26, 2014, 6:57am UTC](https://forum.ansible.com/t/inventory-with-more-than-one-server-per-host/16888/1 "2014-11-26T06:57:37Z")

</div>

Hello,

I am trying to make a playbook with the following inventory work:

###### hosts

[applicationservers:children]  
dev1\_appserver  
dev2\_appserver

[dev1\_appserver]  
host1

[dev2\_appserver]  
host1

[dev1\_appserver:vars]  
appserver\_name=dev1  
appserver\_home=“somepath/dev1/…”  
appserver\_port=“9090”

[dev2\_appserver:vars]  
appserver\_name=dev2  
appserver\_home=“somepath/dev2/…”  
appserver\_port=“8080”

---

<div class="post-metadata">

**Author:** ![rektide](https://avatars.discourse-cdn.com/v4/letter/r/a88e57/32.png) [@rektide](https://forum.ansible.com/u/rektide)\
**Post date:** [November 26, 2014, 3:17pm UTC](https://forum.ansible.com/t/inventory-with-more-than-one-server-per-host/16888/2 "2014-11-26T15:17:47Z")

</div>

I've had similar issues in my time using Ansible. Often I want to test clusterware  
locally beforehand- maybe run 3 etcd instances on one server to validate the config.

Adding additional IP addresses with new hostnames to the host allows me to get by,  
but it's solidly in the realm of dirty hack and I'd love to see ansible grow to  
support this use case.

---

<div class="post-metadata">

**Author:** ![Hugo\_Posca](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@Hugo\_Posca](https://forum.ansible.com/u/Hugo_Posca)\
**Post date:** [November 26, 2014, 5:00pm UTC](https://forum.ansible.com/t/inventory-with-more-than-one-server-per-host/16888/3 "2014-11-26T17:00:46Z")

</div>

Ronny,

One way to deal with this is: instead of configuring 6 different hosts  
(that are actually the same), make your playbook do all the 6 tasks at  
once.

This way you can have a hosts file with something like this:  
[applicationservers]  
host1

Variables defined inside a "vars file", like:  
apps:  
- { name=dev1, home="somepath/dev1/...", port="9090" }  
- { name=dev2, home="somepath/dev2/...", port="8080" }

And in your role:  
tasks:  
&nbsp;&nbsp;-name: deploy our application  
&nbsp;&nbsp;shell: doDeploy.sh {{ appserver\_name }} {{ appserver\_home }} {{  
appserver\_port }}  
&nbsp;&nbsp;with\_items: apps

For more info about managing your roles I'd recommend:  
[http://docs.ansible.com/playbooks\_roles.html](http://docs.ansible.com/playbooks_roles.html) and  
[http://docs.ansible.com/playbooks\_variables.html](http://docs.ansible.com/playbooks_variables.html)

Regards,  
Hugo

---

<div class="post-metadata">

**Author:** ![Ronny](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@Ronny](https://forum.ansible.com/u/Ronny)\
**Post date:** [November 27, 2014, 11:30am UTC](https://forum.ansible.com/t/inventory-with-more-than-one-server-per-host/16888/4 "2014-11-27T11:30:36Z")

</div>

Thank you very much Hugo.  
That is a very good solution that I can work with.

Best regards,  
Ronny

---

<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:** [December 1, 2014, 9:07pm UTC](https://forum.ansible.com/t/inventory-with-more-than-one-server-per-host/16888/5 "2014-12-01T21:07:45Z")

</div>

" It looks like ansible’s smallest unit is the host. But we have here up to 6 application servers per host "

Consider something like a

“with\_items: app\_servers” attached to your task.
