# Restart clustered service node by node?

**URL:** <https://forum.ansible.com/t/restart-clustered-service-node-by-node/19727>\
**Category:** Ansible Project\
**Created:** [November 10, 2015, 2:55pm UTC](https://forum.ansible.com/t/restart-clustered-service-node-by-node/19727 "2015-11-10T14:55:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafal\_Radecki](https://avatars.discourse-cdn.com/v4/letter/r/bcef8e/32.png) [@Rafal\_Radecki](https://forum.ansible.com/u/Rafal_Radecki)\
**Post date:** [November 10, 2015, 2:55pm UTC](https://forum.ansible.com/t/restart-clustered-service-node-by-node/19727/1 "2015-11-10T14:55:36Z")

</div>

Hi All 😉

I currently am writing automation for a Percona Galera cluster which consists of 3 nodes. I am uploading a config file with:

- name: upload my.cnf  
template: src=my.cnf.j2 dest=/etc/my.cnf  
when: “‘db\_cluster’ in group\_names”  
register: db\_cluster\_restart

When the above config file changes I would like to restart the db cluster node by node:

1. restart mysql on 1st cluster node and wait for the restart to finish

2. restart mysql on 2nd cluster node and wait for the restart to finish

3. restart mysql on 3rd cluster node and wait for the restart to finish

My cluster group is defined this way:

[db-cluster]  
db-cluster-0 ansible\_ssh\_host=192.168.0.1  
db-cluster-1 ansible\_ssh\_host=192.168.0.2  
db-cluster-2 ansible\_ssh\_host=192.168.0.3

What is the best way to achieve this kind of functionality?

BR,  
Rafal.

---

<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 10, 2015, 6:35pm UTC](https://forum.ansible.com/t/restart-clustered-service-node-by-node/19727/2 "2015-11-10T18:35:52Z")

</div>

set `serial: 1` at the play level it will force the tasks to all run  
for one host at a time, combine that with wait\_for to test that the  
mysql db is back up.

---

<div class="post-metadata">

**Author:** ![Rafal\_Radecki](https://avatars.discourse-cdn.com/v4/letter/r/bcef8e/32.png) [@Rafal\_Radecki](https://forum.ansible.com/u/Rafal_Radecki)\
**Post date:** [November 12, 2015, 10:38am UTC](https://forum.ansible.com/t/restart-clustered-service-node-by-node/19727/3 "2015-11-12T10:38:57Z")

</div>

Thanks for the tip. Overall serial looks good but it is usable only at the ‘play’ level. In my case I have one play which uploads a template for config file and does many other actions to configure the mysql cluster. I cannot afford setting serial=1 for the whole play and as I see in [http://stackoverflow.com/questions/26685544/rolling-restart-with-ansible-handlers](http://stackoverflow.com/questions/26685544/rolling-restart-with-ansible-handlers) it is not possible to use serial for specific tasks and/or handlers only.

Are there any other options?

---

<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 12, 2015, 4:03pm UTC](https://forum.ansible.com/t/restart-clustered-service-node-by-node/19727/4 "2015-11-12T16:03:03Z")

</div>

you can have more than 1 play in a playbook

- name: play1  
&nbsp;&nbsp;hosts: ...  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- do most of the work

- na
