Using pause module the perform reboot during playbook

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 ?

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

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

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