I am writing a ansible script for my deployment and stuck at one problem. I have 6 tomcat nodes where I have do a rolling deployment i.e. first deploy on 3 nodes and test it. If the test is successful then go for remaining 3 nodes. My current inventory looks like this -
[prod]
prod-1-myapp
prod-2-myapp
prod-3-myapp
prod-4-myapp
prod-5-myapp
prod-6-myapp
[preprod]
preprod-cn-p1
And I am using group_vars where I have prod.yml/preprod.yml
to upload the configuration at run time.
Is it possible to segregate this host group into 2 and deploy on each of them accordingly.
If i create 2 host groups like below, how do i make use of my prod.yml
at run time. How will it work?
[prod-1]
prod-1-myapp
prod-2-myapp
prod-3-myapp
[prod-2]
prod-4-myapp
prod-5-myapp
prod-6-myapp
[preprod]
preprod-cn-p1
My Current query -
ansible-playbook myapp-main.yml -e myapp_release_version=5.0.0 -e target_env=prod
myapp-main.yml
---
- name: Starting with Myapp Application deployment to tomcat nodes
hosts: '{{ target_env }}'
gather_facts: True
any_errors_fatal: true
roles:
- role: deploy
tags:
- deploy
become: yes
become_user: tomcat
become_method: sudo
Please if someone can advice. Any help is appreciated
-e target_env=prod-1
, check if it works and then run the same thing but with-e target_env=prod-2
. – toydariangroup_vars
where I have a file nameprod.yml
which contains all the configurations for production environment. If i use like this-e target_env=prod-1
then how will it pick up those configurations? – Shashank Agrawalprod-1
andprod-2
children of a groupprod
and assign the group vars to the groupprod
so all hosts inprod-1
andprod-2
will pick them up. – toydarian