On Monday, October 30, 2017 at 3:12:51 PM UTC-5, Aleks Przhelyaskovskiy
wrote:
>
> Hello,
>
> Trying to setup rolling deployments for WAS using ansible core.
>
> My environment consists of two groups of hosts. Each group has one
> manager, and two nodes. The deployment process consists of running a task
> on manager host first, and then another tasks on every node in the group
> (including manager). I'd like to run the whole deployment process one group
> at-a-time.
>
> I was thinking about creating a top-level playbook that will loop through
> groups, and pass group name to each play as a parameter. Is there an easy
> way to accomplish this, or is there a better way of doing this?
>
> The example inventory would be:
>
> ----- snip -----
> [groups]
> group1
> group2
>
> [group1:children]
> manager1
> nodes1
>
> [group2:children]
> manager2
> nodes2
>
> [manager1]
> host_m1
>
> [manager2]
> host_m2
>
> [nodes1]
> host_a
> host_b
>
> [nodes2]
> host_c
> host_d
> ----- snip -----
>
>
>
> Thanks in advance.
>
So far, I was able to accomplish only part of my original project. By
passing a variable as an argument when invoking ansible-playbook. So my
command line looks like this:
>ansible-playbook deploy_group.yml -e group_num='1'
My top level playbook deploy_group.yml contains two plays: app_deploy.yml
and post_deploy.yml. I use the group_num variable to limit list of hosts to
members of a single group.
The deploy_group.yml looks like this:
----- ----- begin ----- -----
---
- name: top-level deployment playbook
hosts: 'manager{{ group_num }}'
gather_facts: True
serial: 1
- include: app_deploy.yml
- include: post_deploy.yml
----- ----- end ----- -----
The app_deploy.yml looks like this:
----- ----- begin ----- -----
---
- hosts: 'manager{{ group_num }}'
tasks:
- name: deploy war file
shell: '~/scripts/deploy_war.sh >> /tmp/deploy_war.out'
----- ----- end ----- -----
The post_deploy.yml looks like this:
----- ----- begin ----- -----
---
- hosts: 'manager{{ group_num }}:&nodes{{ group_num }}'
tasks:
- name: restart all java processes
shell: '~/scripts/restart_all.sh >> /tmp/restart_all.log'
----- ----- end ----- -----
This works for individual groups, but requires keeping track of group
numbers and status of playbook execution outside of ansible. Is there a way
to loop through group names, and pass group name to a set of plays at each
iteration?
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/9aa98310-d8fe-4148-993a-5af5e27583a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.