Ansible reboot a Debian/Ubuntu Linux for kernel update and wait for it

To reboot a Debian/Ubuntu Linux machine using Ansible and wait for it to come back online, you can use the “wait_for” module in combination with the “reboot” command. Here is an example playbook that demonstrates how to do this:

- name: reboot and wait for Debian/Ubuntu Linux machine
hosts: all
tasks:
- name: reboot the machine
command: reboot
async: 1
poll: 0
- name: wait for the machine to come back online
wait_for:
host: "{{ ansible_host }}"
port: 22
timeout: 600

In this example, the “reboot” command is used to reboot the machine, and the “async” and “poll” options are set to allow the task to run in the background. The “wait_for” task is then used to wait for the machine to come back online, with a timeout of 600 seconds. Once the machine is back online, the playbook will continue to run.

You could also use ansible reboot -i inventory -b command to reboot the target machine and wait for it to come back online.

Leave a Comment