Ronny
(Ronny)
November 26, 2014, 6:57am
1
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”
rektide
November 26, 2014, 3:17pm
2
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
(Hugo Posca)
November 26, 2014, 5:00pm
3
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
Ronny
(Ronny)
November 27, 2014, 11:30am
4
Thank you very much Hugo.
That is a very good solution that I can work with.
Best regards,
Ronny
" 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.