Chef – Rebooting a node without breaking the run

We’ve found ourselves in a situation where we need to reboot a Windows node after joining the domain, and this was causing the Chef run to fail as the node can’t be contacted. To get around this, simply execute a shutdown asynchronously with the shutdown command.

#Set up reboot after 30 seconds
execute "chef-client" do
command 'shutdown /r /t 30'
action :run

This sets up a reboot in 30 seconds, the Chef run will finish (as long as this is the last thing left) and the machine will come up on the domain.