# Help with rolling deployments

**URL:** <https://forum.ansible.com/t/help-with-rolling-deployments/25870>\
**Category:** Ansible Project\
**Created:** [October 30, 2017, 8:12pm UTC](https://forum.ansible.com/t/help-with-rolling-deployments/25870 "2017-10-30T20:12:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleks\_Przhelyaskovsk](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Aleks\_Przhelyaskovsk](https://forum.ansible.com/u/Aleks_Przhelyaskovsk)\
**Post date:** [October 30, 2017, 8:12pm UTC](https://forum.ansible.com/t/help-with-rolling-deployments/25870/1 "2017-10-30T20:12:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aleks\_Przhelyaskovsk](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Aleks\_Przhelyaskovsk](https://forum.ansible.com/u/Aleks_Przhelyaskovsk)\
**Post date:** [October 31, 2017, 1:31pm UTC](https://forum.ansible.com/t/help-with-rolling-deployments/25870/2 "2017-10-31T13:31:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aleks\_Przhelyaskovsk](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Aleks\_Przhelyaskovsk](https://forum.ansible.com/u/Aleks_Przhelyaskovsk)\
**Post date:** [October 31, 2017, 2:26pm UTC](https://forum.ansible.com/t/help-with-rolling-deployments/25870/3 "2017-10-31T14:26:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 31, 2017, 3:25pm UTC](https://forum.ansible.com/t/help-with-rolling-deployments/25870/4 "2017-10-31T15:25:16Z")

</div>

It's the correct group.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 31, 2017, 3:52pm UTC](https://forum.ansible.com/t/help-with-rolling-deployments/25870/5 "2017-10-31T15:52:31Z")

</div>

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

inventory

---

<div class="post-metadata">

**Author:** ![Aleks\_Przhelyaskovsk](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Aleks\_Przhelyaskovsk](https://forum.ansible.com/u/Aleks_Przhelyaskovsk)\
**Post date:** [October 31, 2017, 6:10pm UTC](https://forum.ansible.com/t/help-with-rolling-deployments/25870/6 "2017-10-31T18:10:59Z")

</div>

> 

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.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 31, 2017, 6:53pm UTC](https://forum.ansible.com/t/help-with-rolling-deployments/25870/7 "2017-10-31T18:53:44Z")

</div>

Something like this

playbook.yml

---

<div class="post-metadata">

**Author:** ![Aleks\_Przhelyaskovsk](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Aleks\_Przhelyaskovsk](https://forum.ansible.com/u/Aleks_Przhelyaskovsk)\
**Post date:** [October 31, 2017, 6:59pm UTC](https://forum.ansible.com/t/help-with-rolling-deployments/25870/8 "2017-10-31T18:59:58Z")

</div>

Kai,

Thank you very much.
