Ansible reboot Module: Restart Hosts and Wait for Recovery (Complete Guide)
By Luca Berton · Published 2024-01-01 · Category: troubleshooting
How to use Ansible reboot module to safely restart servers. Wait for SSH, set timeout, handle kernel updates. Complete guide with playbook examples.
Ansible reboot Module: Restart Hosts and Wait for Recovery (Complete Guide)
The ansible.builtin.reboot module reboot a machine and wait for it to come back. This guide covers all common use cases with practical playbook examples.
Basic Reboot
Reboot with Custom Timeout
Conditional Reboot (Kernel Update)
Reboot and Verify Service
Check if Reboot is Required
FAQ
How do I reboot a server with Ansible?
Use ansible.builtin.reboot. It reboots the host and automatically waits for SSH to become available again before continuing with the next task.
How long does Ansible wait after a reboot?
By default, Ansible waits up to 600 seconds (10 minutes) for the host to come back. Adjust with reboot_timeout. Use post_reboot_delay to add extra wait time after SSH reconnects.
How do I check if a reboot is required in Ansible?
On Debian/Ubuntu, check if /var/run/reboot-required exists with ansible.builtin.stat. On RHEL, run needs-restarting -r and check the return code.
Conclusion
The ansible.builtin.reboot module is a versatile tool for reboot a machine and wait for it to come back. Use the examples above as starting points and adapt them to your infrastructure needs.
Related Articles • Ansible service Module: Manage Services • Ansible wait_for Module
Category: troubleshooting