How to restart a Windows VM using chef

1.8k views Asked by At

My requirement is to restart the windows vm after the software gets installed, I am automating the entire process using chef. Is there any method for doing that?

Can we do through power shell ?
Is there any method for chef to that ?

2

There are 2 answers

1
StephenKing On BEST ANSWER

The windows cookbook offers a reboot resource.

2
Sanderp On

As mentioned above check out the links windows cookbook & windows reboot. All my info is gathered from the previous links.

Include the WindowsRebootHandler in the recipe

include_recipe 'windows::reboot_handler'

Create a reboot block

windows_reboot 30 do
  timeout 30
  reason 'Restarting computer in 30 seconds!'
  action :nothing
end
  • timeout: timeout delay in seconds before rebooting. default is 60 seconds
  • reason: reason for the reboot. default is 'Opscode Chef initiated reboot'

Notify the reboot block to trigger the reboot

notifies :request, 'windows_reboot[30]', :delayed
  • :delayed - notification is queued up and executed at the very end of a chef-client run
  • :immediately - notification is ran immediately