# reboot via ansible 2.4

**URL:** <https://forum.ansible.com/t/reboot-via-ansible-2-4/27004>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [March 15, 2018, 2:21pm UTC](https://forum.ansible.com/t/reboot-via-ansible-2-4/27004 "2018-03-15T14:21:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rraka1002](https://avatars.discourse-cdn.com/v4/letter/r/bcef8e/32.png) [@rraka1002](https://forum.ansible.com/u/rraka1002)\
**Post date:** [March 15, 2018, 2:21pm UTC](https://forum.ansible.com/t/reboot-via-ansible-2-4/27004/1 "2018-03-15T14:21:32Z")

</div>

Hello Friends,

Does anyone have experience using the reboot playbook on RHEL systems, i’m using below method and it reboots the systems but in between while system is rebooting it breaks the connection and does not wait for post reboot status like uptime, if someone already overcomed this please let me know , my play looks like below…

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [March 15, 2018, 3:33pm UTC](https://forum.ansible.com/t/reboot-via-ansible-2-4/27004/2 "2018-03-15T15:33:26Z")

</div>

Hi,

> Hello Friends,
> 
> Does anyone have experience using the reboot playbook on RHEL systems,  
> i'm using below method and it reboots the systems but in between while  
> system is rebooting it breaks the connection and does not wait for  
> post reboot status like uptime, if someone already overcomed this  
> please let me know , my play looks like below...
> 
> ---  
> - name: Reboot a host and wait for it to return  
> hosts: postinstall  
> remote\_user: root
> 
> tasks:  
> - name: check automount  
> service: name=autofs state=stopped
> 
> ```
> \- name: reboot host
> shell: sleep 10 &amp;&amp; /sbin/shutdown \-r now
> async: 360
> poll: 0
> become: true
> 
> ```

Without any log of what's the problem exactly is, it's not so obvious to  
help you... Did you try to add a sleep just after the shutdown (on the  
shell line) like written in this article ?  
[https://stackoverflow.com/questions/23877781/how-to-wait-for-server-restart-using-ansible](https://stackoverflow.com/questions/23877781/how-to-wait-for-server-restart-using-ansible)

> ```
> \- name: waiting for server booting up
> local\_action: wait\_for host=&quot;\{\{ inventory\_hostname \}\}&quot; port=22
> 
> ```
> 
> delay=5 timeout=360
> 
> ```
> \- name: check uptime
> local\_action: shell ansible \-u \{\{ ansible\_user\_id \}\} \-m ping \{\{
> 
> ```
> 
> inventory\_hostname }}  
> register: result  
> until: result.rc == 0  
> retries: 30  
> delay: 10

Why using shell to do an ansible ping ?  
You can use it directly.... Try to always avoid shell module

> ```
> \# And finally, execute &#39;uptime&#39; when the host is back\.
> \- shell: uptime
> 
> ```

There's a fact for this :  
ansible\_uptime\_seconds  
Why not using it ?

Regards,

JYL

---

<div class="post-metadata">

**Author:** ![rraka1002](https://avatars.discourse-cdn.com/v4/letter/r/bcef8e/32.png) [@rraka1002](https://forum.ansible.com/u/rraka1002)\
**Post date:** [March 15, 2018, 4:06pm UTC](https://forum.ansible.com/t/reboot-via-ansible-2-4/27004/3 "2018-03-15T16:06:06Z")

</div>

Thanks JYL, by the way there is no log when i run this play , even system gets rebooted and up but it doesn’t give any clue and breaks the connection .  
Anyway, i will try to debug the logs…

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [March 15, 2018, 4:11pm UTC](https://forum.ansible.com/t/reboot-via-ansible-2-4/27004/4 "2018-03-15T16:11:25Z")

</div>

You can add more verbose with -v and -vv, etc during execution off your  
playbook on the controller site to better understand the problem  
There are a minimum of log on the destination site too, do a grep  
ansible /var/log/messages and you will have some information

Regards,

JYL

---

<div class="post-metadata">

**Author:** ![Mirko\_Friedenhagen](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Mirko\_Friedenhagen](https://forum.ansible.com/u/Mirko_Friedenhagen)\
**Post date:** [March 19, 2018, 5:18am UTC](https://forum.ansible.com/t/reboot-via-ansible-2-4/27004/5 "2018-03-19T05:18:54Z")

</div>

Hello

you wait 10 seconds before calling shutdown but check after 5 seconds whether the port is accessible again.

I use async as well but firstly check via a localaction that the ssh port is drained/not reachable anymore

Best regards  
Mirko
