# Rolling restart using handlers

**URL:** <https://forum.ansible.com/t/rolling-restart-using-handlers/16659>\
**Category:** Ansible Project\
**Created:** [November 1, 2014, 12:46pm UTC](https://forum.ansible.com/t/rolling-restart-using-handlers/16659 "2014-11-01T12:46:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Costi\_Ciudatu](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Costi\_Ciudatu](https://forum.ansible.com/u/Costi_Ciudatu)\
**Post date:** [November 1, 2014, 12:46pm UTC](https://forum.ansible.com/t/rolling-restart-using-handlers/16659/1 "2014-11-01T12:46:51Z")

</div>

Is there a way to run the handlers with a different `serial` value than the rest of the play ?

What I want is to install my services in large batches (usually, on all the machines at once) and if any of those services needs to be restarted, I want to perform that operation on X machines at a time.  
Ideally, the X value should be decided for each particular service: e.g. I want to restart postgresql instances one at a time and I want to restart nginx on 30% of the hosts at a time.  
However, the installation needs to be done on all the machines in parallel, as I usually have no reason to do this sequentially (restarts are rarely required).

Is this possible with handlers ? Or can I trigger handlers from a different play ?  
Or, at least, is there some best practice recommendation for how to achieve this ?

Thanks

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 3, 2014, 12:23pm UTC](https://forum.ansible.com/t/rolling-restart-using-handlers/16659/2 "2014-11-03T12:23:31Z")

</div>

No, handlers run with the play settings, so you can do serial: 30% but that will affect both the install and the handler. The other way to do it is to separate it into 2 plays with different serial, but then they are not really handlers.

---

<div class="post-metadata">

**Author:** ![Azul](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Azul](https://forum.ansible.com/u/Azul)\
**Post date:** [November 11, 2014, 11:41am UTC](https://forum.ansible.com/t/rolling-restart-using-handlers/16659/3 "2014-11-11T11:41:43Z")

</div>

I do this:

# first batch in parallel

6 - hosts:  
7 - apps\_servers  
8 max\_fail\_percentage: 1  
9 accelerate: false  
10 sudo: true  
11 gather\_facts: true  
12  
13 roles:  
14 | - base

# then one box at a time

- hosts:  
26 - apps\_servers  
27 max\_fail\_percentage: 1  
**28 serial: 1**  
29 accelerate: false  
30 sudo: true  
31 gather\_facts: false  
32  
33 pre\_tasks:  
34 - name: remove this host from the load balancer config  
35 | shell: ssh {{ item }} sudo manage-backend-servers {{ inventory\_hostname }} remove  
36 | with\_items: groups[‘lb\_servers’]  
37 | sudo: false  
38 | delegate\_to: 127.0.0.1  
39  
40 roles:  
43 | - apps

11 post\_tasks:  
10 - name: add this host back into the load balancer config  
9 | shell: ssh {{ item }} sudo manage-backend-servers {{ inventory\_hostname }} add  
8 | sudo: false  
7 | delegate\_to: 127.0.0.1  
6 | with\_items: groups[‘lb\_servers’]

# then last batch in parallel again

13 - hosts:  
12 - apps\_servers  
11 max\_fail\_percentage: 1  
10 accelerate: false  
9 sudo: true  
~ 8 gather\_facts: true  
7  
6 roles:  
5 | - do\_the\_rest  
4 | - finish\_up

---

<div class="post-metadata">

**Author:** ![Costi\_Ciudatu](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Costi\_Ciudatu](https://forum.ansible.com/u/Costi_Ciudatu)\
**Post date:** [November 11, 2014, 12:52pm UTC](https://forum.ansible.com/t/rolling-restart-using-handlers/16659/4 "2014-11-11T12:52:46Z")

</div>

Thanks Brian,

I wanted a confirmation for this because I feel like it makes the roles and handlers hardly unusable in a real cluster environment  
and it shouldn’t be addressed with workarounds. I’ll try to see if I can come up with a patch and submit it for review.
