using ansible to deploy war to stage/qa env

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”.

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

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.

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