Ansible, Windows and PowerShell: the Basics – Part 8, Rebooting & Waiting
In Part 8 of this series we’ll continue our journey with Ansible, Windows and PowerShell and look at how to handle reboots. Despite improvements in Windows over the years, it’s still pretty common as part of VM or application deployment to need to restart the VM and wait for it to be available before carrying on with some further steps.
The following example will demonstrate how to use the win_reboot and win_wait_for modules to reboot a VM and wait for the RDP port 3389 to be available before carrying on.
Our job template in AWX is _7_reboot_and_wait
The contents of _7_reboot_and_wait.yml are are follows:
The first task reboots the VM using the default options, which includes running a test command of whoami in the VM to confirm it has started.
This can be expanded further in the second task by waiting for a particular to become available. In this example we use the RDP port 3389 to confirm that the VM is ready for us to continue with any further automation.
Running a job from the _7_reboot_and_wait job template produces the following result:
The VM was successfully rebooted and we waited for port 3389 to be responsive before continuing further.
- Ansible, Windows and PowerShell: the Basics – Introduction
- Ansible, Windows and PowerShell: the Basics - Part 1, Windows Services
- Ansible, Windows and PowerShell: the Basics - Part 2, Install PowerShell Modules
- Ansible, Windows and PowerShell: the Basics – Part 3, Windows Roles and Features
- Ansible, Windows and PowerShell: the Basics – Part 4, Invoking PowerShell Code
- Ansible, Windows and PowerShell: the Basics – Part 5, Example PowerShell Error Handling
- Ansible, Windows and PowerShell: the Basics – Part 6, Displaying Output from PowerShell Code
- Ansible, Windows and PowerShell: the Basics – Part 7, Utilising PowerShell DSC
- Ansible, Windows and PowerShell: the Basics – Part 8, Rebooting & Waiting
- Ansible, Windows and PowerShell: the Basics – Part 9, Disk Creation
- Ansible, Windows and PowerShell: the Basics – Part 10, Local Users
- Ansible, Windows and PowerShell: the Basics – Part 11, Local Groups
- Ansible, Windows and PowerShell: the Basics – Part 12, Set TimeZone
- Ansible, Windows and PowerShell: the Basics – Part 13, Environment Variables
- Ansible, Windows and PowerShell: the Basics – Part 14, Registry Entries
- Ansible, Windows and PowerShell: the Basics – Part 15, Install Chocolatey Packages