using ansible to deploy war to stage/qa env

Hi !

I currently using python tools for continuous deloy to AWS ec2 nodes and want to use ansible for continuous deploy. We have stage and qa env with different properties. Could someone point to me the right approach to setup continuous deploy to mulitple env with the right properties.

Thanks,
Olga S

I recommend keeping your inventory in a directory, like inventory/

and then have a inventory/production and a inventory/stage

This prevents accidentally running something against both as you’ll have to -i inventory/stage (unless you type -i inventory!)

Usage of group_vars is then the way to organize variance between them.

See http://docs.ansible.com/playbooks_best_practices.html#how-to-arrange-inventory-stage-vs-production

Sorry, I’m new here. Can you elaborate a bit on how this would work?

The docs recommend a setup like this

production                # inventory file for production servers
stage                     # inventory file for stage environment

group_vars/
   group1                 # here we assign variables to particular groups
   group2                 # ""
host_vars/
   hostname1              # if systems need specific variables, put them here
   hostname2              # ""

So instead you’re recommending this?

inventory/production                # inventory file for production servers
inventory/stage                     # inventory file for stage environment

group_vars/
   group1                 # here we assign variables to particular groups
   group2                 # ""

So with that setup would you need to use different group names in the inventories so you can set them separately in the global group_vars?
If I want to use the same group names in my production and stage inventories, will something like this work?

inventory/production/inventory                # inventory file for production servers
inventory/stage/inventory                     # inventory file for stage environment

inventory/production/group_vars/
   group1                 # here we assign variables to production group1

I wrote those docs :slight_smile:

You have this part slightly off:

inventory/production                # inventory file for production servers
inventory/stage                     # inventory file for stage environment

group_vars/
   group1                 # here we assign variables to particular groups
   group2                 # ""
Drop the group_vars directory inside inventory, so like inventory/group_vars/group1.
Then it just works.  group_vars must be alongside the inventory files, but "-i inventory_dir" is a shortcut to run multiple inventory files at the same time, should you ever want to.  
Still use groups and have groups for production and stage, because you may want them in your playbooks to assign different variable settings to them. 

Thanks! That clears it up.

With this schema,

inventory/production                # inventory file for production servers
inventory/stage                     # inventory file for stage environment

inventory/group_vars/
   group1                 # here we assign variables to particular groups
   group2                 # ""

can vars have different values on every environment? Or must group names be different on every environment?

Jordi Funollet <funollet@fastmail.fm> napisał:

With this schema,

inventory/production # inventory file for production
serv
ers
inventory/stage # inventory file for stage
environme
nt

inventory/group_vars/
group1 # here we assign variables to particular group
s
group2 # ""

can vars have different values on every environment? Or must
group names be different on every environment?

You'd have to have different group names, or move the differing vars into inventories.
You can also use a schema like this:

production/group_vars/...
production/inventory
staging/group_vars/...
staging/inventory

group_vars/... # those are common
playbookA.yml
playbookB.yml
site.yml

No, you cannot do what Tomas says above and then still target “-i inventory” as one common infrastructure.

instead, do this.

Inside your inventory/production put all hosts under a group named “production”

Inside your inventory/stage, put all hosts under a group named “stage”.

But then I miss the ability to run a task in a group of a specific
environment (say, just on production hosts of group 'dbservers' ). Am I
right? Or is there a way to express this?

hosts can be in more than one group. all hosts in the production file should be in production group, but you can also have hosts in dbservers group.​

Take a look at --limit to refine execution to a specific subgroup, or additional parameters on the host specifier like:

  • hosts: webservers:&phoenix

To select all webservers in phoenix

–limit phoenix does the same thing as adding “:&phoenix” to all host specifiers.

I forgot the ':&' operator. Thanks Michael.