AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 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 "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, 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 win_reboot Module: Reboot Windows & Wait for Recovery (Guide)

By Luca Berton · Published 2024-01-01 · Category: troubleshooting

How to reboot Windows hosts with Ansible win_reboot module (ansible.windows.win_reboot). Restart Windows, wait for WinRM, set timeouts. Practical YAML playbook examples.

How to reboot remote Windows 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 Windows hosts Today we're talking about Ansible module win_reboot. The full name is ansible.windows.win_reboot which means is part of the ansible.windows collection collection to target Windows host. The purpose is to reboot a Windows machine, wait for it to go down, come back up, and respond to commands. For non-Windows targets, use the ansible.builtin.reboot module instead. Please note that the connection user must have the SeRemoteShutdownPrivilege Windows privilege enabled.

Parameters • reboot_timeout float - 600 • msg string - "Reboot initiated by Ansible" • connect_timeout float - 5 • pre_reboot_delay float - 2 • post_reboot_delay float - 0 • test_command string - "detect Windows Logon" • boot_time_command string - (Get-CimInstance -ClassName Win32_OperatingSystem -Property LastBootUpTime).LastBootUpTime.ToFileTime()

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 connection to the target host is performed by WinRM TCP connection, with a timeout default to 5 seconds, which you could customize using the "connect_timeout" parameter. 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 Windows reboot command. You could define also some extra delay time using the "pre_reboot_delay" or "post_reboot_delay" integer. The first is default to two and the second to zero seconds. Once rebooted the target host Ansible is going to verify the workstation fully working using a test command. The default script detects when the Windows Logon screen is up and ready to accept credentials, but you could customize using the "test_command" parameter. An example about a specific service: exit (Get-Service -Name Netlogon).Status -ne "Running"' This module could return also the amount of time indeed for bootstrap process reading thow Windows system, specifically (Get-CimInstance -ClassName Win32_OperatingSystem -Property LastBootUpTime).LastBootUpTime.ToFileTime().

## Playbook Let's jump into a real-life playbook on how to reboot a Windows remote host with Ansible Playbook.

code • win_reboot.yml

execution output

code with ❤️ in GitHub

Conclusion

Now you know how to reboot Windows hosts with Ansible.

Related ArticlesAnsible Become GuideAnsible Inventory GuideAnsible Roles GuideAnsible for Windows Guide

Category: troubleshooting

Watch the video: Ansible win_reboot Module: Reboot Windows & Wait for Recovery (Guide) — Video Tutorial

Browse all Ansible tutorials · AnsiblePilot Home