Inventory with more than one server per host

74 views
Skip to first unread message

Ronny

unread,
Nov 26, 2014, 1:57:37 AM11/26/14
to ansible...@googlegroups.com, sven.op...@gmail.com, oriol.triq...@capgemini.com

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"

########################
 
They share the same host, it's not mistake. If I write a playbook like this:

###### playbook
- hosts: applicationservers
 tasks:
 -name: deploy our application
 shell: doDeploy.sh {{ appserver_name }} {{ appserver_home }} {{ appserver_port }}
################################################
 
If I run this, the task "deploy our application" is only executed once. It looks like ansible's smallest unit is the host. But we have here up to 6 application servers per host and want to deploy them at once.
How should the inventory look like?

Thank you!

rek...@voodoowarez.com

unread,
Nov 26, 2014, 10:17:52 AM11/26/14
to ansible...@googlegroups.com, sven.op...@gmail.com, oriol.triq...@capgemini.com
On Tue, Nov 25, 2014 at 10:57:37PM -0800, Ronny wrote:

> If I run this, the task "deploy our application" is only executed once. It
> looks like ansible's smallest unit is the host. But we have here up to 6
> application servers per host and want to deploy them at once.
> How should the inventory look like?

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.

Hugo Posca

unread,
Nov 26, 2014, 12:12:05 PM11/26/14
to ansible...@googlegroups.com, sven.op...@gmail.com, oriol.triq...@capgemini.com
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:
-name: deploy our application
shell: doDeploy.sh {{ appserver_name }} {{ appserver_home }} {{
appserver_port }}
with_items: apps

For more info about managing your roles I'd recommend:
http://docs.ansible.com/playbooks_roles.html and
http://docs.ansible.com/playbooks_variables.html

Regards,
Hugo
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20141126151747.GX17066%40voodoowarez.com.
> For more options, visit https://groups.google.com/d/optout.

Ronny

unread,
Nov 27, 2014, 6:30:36 AM11/27/14
to ansible...@googlegroups.com
Thank you very much Hugo.
That is a very good solution that I can work with.

Best regards,
Ronny

Michael DeHaan

unread,
Dec 1, 2014, 4:07:49 PM12/1/14
to ansible...@googlegroups.com
" 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.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages