# Wait for service restart

**URL:** <https://forum.ansible.com/t/wait-for-service-restart/34604>\
**Category:** Ansible Project\
**Created:** [February 10, 2021, 3:51pm UTC](https://forum.ansible.com/t/wait-for-service-restart/34604 "2021-02-10T15:51:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehdi\_Khlifi](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mehdi\_Khlifi](https://forum.ansible.com/u/Mehdi_Khlifi)\
**Post date:** [February 10, 2021, 3:51pm UTC](https://forum.ansible.com/t/wait-for-service-restart/34604/1 "2021-02-10T15:51:05Z")

</div>

Hey guys,

Is there a way to restart a service and wait for it to finish?  
I’m starting Keepalived using the service module and apparently it takes a few seconds to actually start after installation so it’s throwing me an error.

- name: “Start Keepalived”  
service:  
name: keepalived  
state: start

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 10, 2021, 3:54pm UTC](https://forum.ansible.com/t/wait-for-service-restart/34604/2 "2021-02-10T15:54:11Z")

</div>

You can use the 'wait\_for' module, just need a condition that verifies  
the service is up, sadly most 'service managers' report the success of  
'startup command' and not that the service is actually up.

Alternatively you can use service\_facts to check for the service  
status in an until loop that wait for it's success (assuming service  
manager reports correct status).
