Using pause module the perform reboot during playbook

2,456 views
Skip to first unread message

Gregory Shulov

unread,
Oct 21, 2012, 8:08:17 AM10/21/12
to ansible...@googlegroups.com
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 ?

Jeroen Hoekx

unread,
Oct 21, 2012, 8:40:05 AM10/21/12
to ansible...@googlegroups.com
Hello,

On 21 October 2012 14:08, Gregory Shulov <gregory...@gmail.com> wrote:

> 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"

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

Geoffrey Widdel

unread,
Feb 11, 2014, 2:26:56 PM2/11/14
to ansible...@googlegroups.com
This does not work...please test your code before posting.

Christopher O'Connell

unread,
Feb 16, 2014, 9:44:37 PM2/16/14
to ansible...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages