# using ansible to deploy war to stage/qa env

**URL:** <https://forum.ansible.com/t/using-ansible-to-deploy-war-to-stage-qa-env/16060>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [August 28, 2014, 8:31am UTC](https://forum.ansible.com/t/using-ansible-to-deploy-war-to-stage-qa-env/16060 "2014-08-28T08:31:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jordi\_Funollet](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@Jordi\_Funollet](https://forum.ansible.com/u/Jordi_Funollet)\
**Post date:** [August 28, 2014, 8:31am UTC](https://forum.ansible.com/t/using-ansible-to-deploy-war-to-stage-qa-env/16060/1 "2014-08-28T08:31:14Z")

</div>

Agree. So when targeting hosts we can use the inventory as environment and _–limit_ to restrict to a specific group in this environment.

$ ansible-playbook -i inventory/stage -l dbservers

But what about vars? Both vars in _group\_vars/stage_ and _group\_vars/dbservers_ would apply for these hosts. But I can’t see a way to set a value for _dbservers_ in _stage_ and another for _dbservers_ in _production_. Most cases could be addressed without this level of granularity, but I would like to know if there’s some way to achieve this.

And which one takes precedence? I assume groups are sorted alphabetically (are they?) so we should use some naming trick to guarantee that environments vars are consistently selected after (or before) “regular groups” vars.

$ python -c ‘import string ; print “”.join(sorted(string.printable))’

!"#$%&'()\*+,-./0123456789:;\<=\>?@

ABCDEFGHIJKLMNOPQRSTUVWXYZ^\_`abcdefghijklmnopqrstuvwxyz{|}~

Prepending _~_ to environment names sounds like a good way to give them less weight than “regular groups”.

---

<div class="post-metadata">

**Author:** ![Mark\_McCoy](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@Mark\_McCoy](https://forum.ansible.com/u/Mark_McCoy)\
**Post date:** [August 28, 2014, 3:00pm UTC](https://forum.ansible.com/t/using-ansible-to-deploy-war-to-stage-qa-env/16060/2 "2014-08-28T15:00:52Z")

</div>

Here’s an example of how we lay out our ansible project directory. We have a tomcat-based app and we create an RPM for the “common” portions of the app that live outside of the WAR file to be installed (log dir, extra libs, etc), and keep the WAR and the config files specific to each inst-env pair inside of the files/env/inst-env directory.

[https://gist.github.com/BradGunnerSGT/ba1cea6c6629a702f9eb](https://gist.github.com/BradGunnerSGT/ba1cea6c6629a702f9eb)

Using the group\_vars we can specify a different version of the application to be installed onto each environment (to test new versions, for example), and even a different revision of the RPM.

---

<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:** [August 28, 2014, 9:03pm UTC](https://forum.ansible.com/t/using-ansible-to-deploy-war-to-stage-qa-env/16060/3 "2014-08-28T21:03:11Z")

</div>

You can make a group called db\_servers\_stage and db\_servers\_production if you like. Put hosts in each.

[stage:children]  
dbservers\_stage  
webservers\_stage

[dbservers:children]  
dbservers\_stage  
dbservers\_production

etc
