windowschef-infratest-kitchen

Chef reboot resource causes chef run to time out before Windows server is able to start back up after update and resume recipe


I am trying to create a domain on a windows 2012 R2 server and it requires a reboot before the recipe can proceed:

reboot "reboot server" do
  reason "init::chef - continue provisioning after reboot"
  action :reboot_now
end

I receive the following error, which indicates a timeout + it occurs before I see the OS comes back to life after the update:

Failed to complete #converge action: [WinRM::WinRMAuthorizationError] on default-windows2012r2

Does anyone out there know how to make the chef server continue to run after the OS is back up? I hear that :restart_now is supposed to do the trick... ^^^ but as you can see, it isn't :)

P.S. this also causes windows to update... Goal: get chef to resume after the update is complete and the server is back up

Update: The server actually seems to be rebooting twice and exiting the chef run on the second reboot. If I remove the ONE reboot resource block that I have then it does not reboot at all (that makes no sense to me)... here is output from the chef run:

Chef Client finished, 2/25 resources updated in 19 seconds
   [2018-10-29T08:04:11-07:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"init::chef - continue provisioning after reboot", :timestamp=>2018-10-29 08:04:11 -0700, :requested_by=>"reboot server"}
    Running handlers:
       [2018-10-29T08:04:11-07:00] ERROR: Running exception handlers
       Running handlers complete
       [2018-10-29T08:04:11-07:00] ERROR: Exception handlers complete
       Chef Client failed. 2 resources updated in 20 seconds
       [2018-10-29T08:04:11-07:00] FATAL: Stacktrace dumped to C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/chef-stacktrace.out
       [2018-10-29T08:04:11-07:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2018-10-29T08:04:11-07:00] FATAL: Chef::Exceptions::Reboot: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"init::chef - continue provisioning after reboot", :timestamp=>2018-10-29 08:04:11 -0700, :requested_by=>"reboot server"}

^^^ that repeats twice ^^^

Update #2: I even commented out every line except for the reboot block and am experiencing the same issue... this is ridiculous and I'm confident that it isn't my code that is the problem (considering that all I am using now is a reboot command).

Update #3: I generated an entirely new cookbook and called it "reboot"... it contains the following code:

reboot 'app_requires_reboot' do
    action :request_reboot
    reason 'Need to reboot when the run completes successfully.'
end

And unfortunately, it too reboots the Windows server twice... Here are the logs:

Recipe: reboot::default
         * reboot[app_requires_reboot] action request_reboot[2018-10-29T10:21:41-07:00] WARN: Reboot requested:'app_requires_reboot'

           - request a system reboot to occur if the run succeeds

       Running handlers:
       Running handlers complete
       Chef Client finished, 1/1 resources updated in 03 seconds
       [2018-10-29T10:21:41-07:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"Need to reboot when the run completes successfully.", :timestamp=>2018-10-29 10:21:41 -0700, :requested_by=>"app_requires_reboot"}

       Running handlers:
       [2018-10-29T10:21:41-07:00] ERROR: Running exception handlers
       Running handlers complete
       [2018-10-29T10:21:41-07:00] ERROR: Exception handlers complete
       Chef Client failed. 1 resources updated in 03 seconds
       [2018-10-29T10:21:41-07:00] FATAL: Stacktrace dumped to C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/chef-stacktrace.out
       [2018-10-29T10:21:41-07:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2018-10-29T10:21:41-07:00] FATAL: Chef::Exceptions::Reboot: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"Need to reboot when the run completes successfully.", :timestamp=>2018-10-29 10:21:41 -0700, :requested_by=>"app_requires_reboot"}

seems like an issue with chef now... this is bad... who has ever successfully rebooted windows with Chef before? and why does a single reboot block, reboot the server twice?

Update number 4 will be after I have thrown my computer out the window


Solution

  • The issue was resolved with the following logic:

    reboot "reboot server" do
      reason "init::chef - continue provisioning after reboot"
      action :nothing
      only_if {reboot_pending?}
    end
    

    Adding the only if statement allows the recipe to ski[p that step if the OS does not detect that there is a Windows update pending.

    I had forgotten that windows actually does track whether a system update/reboot is required.

    As part of my poweshell_script block, I included the following: notifies :reboot_now, 'reboot[reboot server]', :immediately