using ansible to deploy war to stage/qa env

1,316 views
Skip to first unread message

olga

unread,
Aug 15, 2014, 1:10:54 PM8/15/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Aug 16, 2014, 10:58:45 AM8/16/14
to ansible...@googlegroups.com
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.


--
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/d42530f6-a77d-4a13-9506-b4948efeb003%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Finch

unread,
Aug 24, 2014, 9:22:58 AM8/24/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Aug 24, 2014, 9:50:52 AM8/24/14
to ansible...@googlegroups.com
I wrote those docs :)

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. 


Brian Finch

unread,
Aug 24, 2014, 10:29:50 AM8/24/14
to ansible...@googlegroups.com
Thanks! That clears it up.

Jordi Funollet

unread,
Aug 26, 2014, 9:44:06 AM8/26/14
to ansible...@googlegroups.com
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 Pujol
 

Tomasz Kontusz

unread,
Aug 26, 2014, 12:24:50 PM8/26/14
to ansible...@googlegroups.com


Jordi Funollet <funo...@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

>--
>
>Jordi Funollet Pujol
>
>http://www.linkedin.com/in/jordifunollet

--
Wysłane za pomocą K-9 Mail.

Michael DeHaan

unread,
Aug 26, 2014, 6:57:18 PM8/26/14
to ansible...@googlegroups.com
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".




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

Jordi Funollet

unread,
Aug 27, 2014, 5:25:47 AM8/27/14
to ansible...@googlegroups.com
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?

Brian Coca

unread,
Aug 27, 2014, 10:03:04 PM8/27/14
to ansible...@googlegroups.com
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.​ 

Jordi Funollet

unread,
Aug 28, 2014, 4:31:20 AM8/28/14
to ansible...@googlegroups.com
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".

Mark McCoy

unread,
Aug 28, 2014, 11:01:19 AM8/28/14
to ansible-project
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.


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

Michael DeHaan

unread,
Aug 28, 2014, 5:02:16 PM8/28/14
to ansible...@googlegroups.com
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.




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

Michael DeHaan

unread,
Aug 28, 2014, 5:03:17 PM8/28/14
to ansible...@googlegroups.com
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




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

Jordi Funollet

unread,
Aug 29, 2014, 8:54:52 AM8/29/14
to ansible...@googlegroups.com
I forgot the ':&' operator. Thanks Michael.
Reply all
Reply to author
Forward
0 new messages