Help with rolling deployments

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.

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?

Is this the correct group to ask for help with playbooks, or is there a more-appropriate group. Thx.

It's the correct group.

You have a few options, one of them is something like this.

inventory

Kai,

Thank you for your reply. Your solution is indeed clean, and simple. It will work well for the exact problem I’ve described.
However, I would like to explore a more generic case where one may need to run the same group of tasks /roles on N groups, where N can be between 1 and 8. Just trying to minimize redundant code.

Thanks again.

Something like this

playbook.yml

Kai,

Thank you very much.