Reboot remote hosts - Ansible module reboot
How to reboot remote hosts with Ansible specifying the notification message to logged users, the delay seconds, and the verification command.
How to reboot remote hosts with Ansible?
I’m going to show you a live demo 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
.
The Best Resources For Ansible
Certifications
- Coursera Pro - Unlimited access to 7,000+ world-class courses, hands-on projects, and job-ready certificate programs—all included in your subscription
Video Course
Printed Book
-
Ansible For VMware by Examples
-
Ansible for Kubernetes by Example
-
Hands-on Ansible Automation
-
Red Hat Ansible Automation Platform
eBooks
- Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
- Ansible Cookbook: A Comprehensive Guide to Unleashing the Power of Ansible via Best Practices, Troubleshooting, and Linting Rules with Luca Berton
- Terraform By Example: A Practical Approach for Beginners to Learn Cloud Infrastructure with Terraform
- Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
- Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
- Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
- Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
- Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
- Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
- Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
- Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
- Ansible Automation Platform By Example: A step-by-step guide for the most common user scenarios
demo
Let’s jump into a real-life playbook on how to reboot remote hosts with Ansible Playbook.
- reboot.yml
---
- name: reboot module demo
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"
Recap
Now you know how to reboot remote Linux hosts with Ansible. Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.
Academy
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate