# Using pause module the perform reboot during playbook

**URL:** <https://forum.ansible.com/t/using-pause-module-the-perform-reboot-during-playbook/12007>\
**Category:** Ansible Project\
**Created:** [October 21, 2012, 12:08pm UTC](https://forum.ansible.com/t/using-pause-module-the-perform-reboot-during-playbook/12007 "2012-10-21T12:08:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory\_Shulov](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gregory_shulov/32/4135_2.png) [@Gregory\_Shulov](https://forum.ansible.com/u/Gregory_Shulov)\
**Post date:** [October 21, 2012, 12:08pm UTC](https://forum.ansible.com/t/using-pause-module-the-perform-reboot-during-playbook/12007/1 "2012-10-21T12:08:17Z")

</div>

Hi All,

I am trying to update kernel in playbook and reboot the server without existing playbook.

Here is the example:

# Temprorary hack that fixes mismatched kernel and kernel module versions

- name: “Restart VM to Load new kernel”  
action: command /sbin/reboot  
only\_if: “${foo.stdout} != 0”

- name: “Pause playbook and wait for VM to boot”  
action: pause minutes=2  
only\_if: “${foo.stdout} != 0”

Here is the output:

TASK: [Restart VM to Load new kernel] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [1.1.1.10]

TASK: [Pause playbook and wait for VM to boot] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
(^C-c = continue early, ^C-a = abort)  
[1.1.1.10]  
Pausing for 120 seconds  
fatal: [1.1.1.10] =\> Failed to open session: SSH session not active

Is it even possible ?

---

<div class="post-metadata">

**Author:** ![Jeroen\_Hoekx](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@Jeroen\_Hoekx](https://forum.ansible.com/u/Jeroen_Hoekx)\
**Post date:** [October 21, 2012, 12:40pm UTC](https://forum.ansible.com/t/using-pause-module-the-perform-reboot-during-playbook/12007/2 "2012-10-21T12:40:05Z")

</div>

Hello,

> I am trying to update kernel in playbook and reboot the server without  
> existing playbook.
> 
> Here is the example:
> 
> # Temprorary hack that fixes mismatched kernel and kernel module versions  
> - name: "Restart VM to Load new kernel"  
> &nbsp;&nbsp;action: command /sbin/reboot  
> &nbsp;&nbsp;only\_if: "${foo.stdout} != 0"
> 
> - name: "Pause playbook and wait for VM to boot"  
> &nbsp;&nbsp;action: pause minutes=2  
> &nbsp;&nbsp;only\_if: "${foo.stdout} != 0"

What you need is the wait\_for module.

action: command /sbin/reboot  
local\_action: wait\_for host=${inventory\_hostname} port=22 state=stopped  
local\_action: wait\_for host=${inventory\_hostname} port=22

This should wait until SSH is available. If that does not work  
reliably, the host is down before the first wait\_for launches for  
example, you can remove the first wait\_for and add a 'delay' parameter  
to the second one.

Greetings,

Jeroen

---

<div class="post-metadata">

**Author:** ![Geoffrey\_Widdel](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@Geoffrey\_Widdel](https://forum.ansible.com/u/Geoffrey_Widdel)\
**Post date:** [February 11, 2014, 7:26pm UTC](https://forum.ansible.com/t/using-pause-module-the-perform-reboot-during-playbook/12007/3 "2014-02-11T19:26:56Z")

</div>

This does not work…please test your code before posting.

---

<div class="post-metadata">

**Author:** ![Christopher\_O\_Connel](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@Christopher\_O\_Connel](https://forum.ansible.com/u/Christopher_O_Connel)\
**Post date:** [February 17, 2014, 2:44am UTC](https://forum.ansible.com/t/using-pause-module-the-perform-reboot-during-playbook/12007/4 "2014-02-17T02:44:37Z")

</div>

Here’s a snippet from a playbook I use to update CentOS machines to the CentOSPlus kernel including a reboot (if necessary)

- name: update the kernel  
yum: name=kernel\* state=latest  
register: kernelup
- name: reboot the system  
command: reboot  
when: kernelup.changed
- name: wait for ssh to come back up  
local\_action: wait\_for host={{ ansible\_fqdn }} port=22 delay=120 timeout=900 state=started  
when: kernelup.changed

The nice thing about this is that it _won’t_ reboot the machine if the kernel was already up to date.

(Obviously, in this example the osplus repo needs to have been enabled previosly, using lineinfile or by sending a custom repo definition file. Nonetheless, these commands should work fairly well).

All the best,

~ Christopher
