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.