AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Ansible Reboot Module: Safely Reboot Servers & Wait for Recovery — Video Tutorial
How to reboot remote hosts with Ansible reboot module. Safely reboot servers, wait for recovery, set timeouts, and handle kernel updates with examples.
What You'll Learn
- How to reboot remote hosts with Ansible?
- Ansible reboot remote hosts
- Parameters
- Conclusion
- Basic Reboot
- Reboot with Custom Timeouts
- Conditional Reboot
- Reboot only if kernel was updated
- Reboot only if RHEL needs it
- Rolling Reboot (Zero Downtime)
Full Tutorial Content
How to reboot remote hosts with Ansible?
I'm going to show you a live Playbook with some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot.
Ansible reboot remote hosts
Today we're talking about the Ansible module `reboot`.
The full name is `ansible.builtin.reboot` which means is part of the collection of modules "builtin" with ansible and shipped with `ansible-core`.
This module is pretty stable and out for years and supports a large variety of operating systems.
The purpose is to reboot a remote machine, wait for it to go down, come back up, and respond to commands.
For Windows targets, use the `ansible.windows.win_reboot` module instead.
Parameters
- reboot_timeout _integer_ - 600
- msg _string_ - "Reboot initiated by Ansible"
- reboot_command _string_ - "[OS specific]"
- pre_reboot_delay _integer_ - 0
- post_reboot_delay _integer_ - 0
- test_command string - "whoami"
- boot_time_command string - "cat /proc/sys/kernel/random/boot_id"
This module has not required parameters but some of them might are nice to know.
Let me summarize the most useful parameters.
The "reboot_timeout" defines how much time to expect before a machine returns up & running. The real timeout is double because of the process of reboot and test command success.
The first step in the reboot process is to print a message to all the logged users. You could keep the default "Reboot initiated by Ansible" or customize using the "msg" parameter.
Secondly is going to execute the reboot command, OS-specific. If you need a specific one, please customize the "reboot_command" parameter.
You could define also some extra delay time using the "pre_reboot_delay" or "post_reboot_delay" integer. Both default to zero.
Once rebooted the target host Ansible is going to verify the workstation fully working using a test command. The default is `whoami`, but you could customize using the "test_command" parameter.
This module could return also the amount of time indeed for bootstrap process reading throw kernel, specifically `/proc/sys/kernel/random/boot_id`.
## Playbook
Let's jump into a real-life playbook on how to reboot remote hosts with Ansible Playbook.
- reboot.yml
```yaml
---
- name: reboot module Playbook
hosts: all
become: true
tasks:
- name: reboot host(s)
ansible.builtin.reboot:
msg: "reboot by Ansible"
pre_reboot_delay: 5
post_reboot_delay: 10
test_command: "whoami"
```
[code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/tree/master/reboot%20remote%20hosts)
Conclusion
Now you know how to reboot remote Linux hosts with Ansible.
Basic Reboot
```yaml
- name: Reboot the server
ansible.builtin.reboot:
become: true
```
The module automatically waits for the host to come back online.
Reboot with Custom Timeouts
```yaml
- name: Reboot with extended timeout
ansible.builtin.reboot:
reboot_timeout: 600 # Wait up to 10 min for reboot
connect_timeout: 30 # SSH
About This Tutorial
- Author: Luca Berton
- Difficulty: Advanced
- Read time: 8 min
- Category: troubleshooting
Read the full written article: Ansible Reboot Module: Safely Reboot Servers & Wait for Recovery
Related Video Tutorials
- Three options to Safely Limit Ansible Playbooks Execution to a Single Machine — Three options to safely limit Ansible Playbook execution to a single machine using runtime parameters, playbook code, and variables.
- Ansible Set File Permissions 755: chmod with file Module Guide — How to set file permissions with Ansible file module. Add execute permission (755, 644, 600), manage ownership, and apply permissions recursively.
- How to Add a Disk to a VMware VM Using Ansible Playbook — Learn how to add a disk to a VMware VM using an Ansible playbook. This guide includes the YAML configuration, variables, and execution steps for easy.
- Add Secondary Groups to Linux Users with Ansible Playbook — Learn how to add secondary groups to Linux users with an Ansible playbook. This step-by-step guide includes YAML configuration and execution details.
- ansible.builtin.command Module: Run Ad-Hoc Commands & Tasks (Guide) — How to run commands with Ansible command module (ansible.builtin.command). Execute ad-hoc tasks, manage remote systems, capture output with register.
- What’s New in Red Hat Ansible Automation Platform 2.6 — Explore Red Hat Ansible Automation Platform 2.6, featuring the new automation dashboard, Lightspeed Intelligent Assistant, and self-service automation portal.