How to do a simple reboot with ansible and resume the playbook ?

May be you know, I do some tutorials in devops world.

Recently I start a playlist about ansible, a great tool for the infrastructure as code. This is an beginners playlist to learn step by step to understand and use it.

In a new video, I explain how to use the reboot module, a very simple but powerfull module. With it, you can reboot a server. But ansible can restart the server and check it after the reboot and resume the playbook to do the rest of tasks.

This is very useful, for example, to do a dist upgrade or kernel upgrade who need a reboot after.

For example, you can do it like this :

- name: update cache
apt:
update_cache: yes
force_apt_get: yes
cache_valid_time: 3600

- name: dist upgrade
apt:
upgrade: dist
force_apt_get: yes

- name: check the reboot-required file
register: reboot_required_file
stat:
path: /var/run/reboot-required
register: reboot_required_file

- name: launch the reboot
reboot:
msg: "Reboot with ansible..."
connect_timeout: 5
reboot_timeout: 300
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: uptime
when: reboot_required_file.stat.exists
Credits : https://wallhaven.cc/w/47qg5o

Microservices architecture and opensource. I’m maintainer of xavki https://youtube.com/c/xavki-linux about opensource. My blog : https://xavki.blog/