Chef includes a reboot
resource which allows rebooting a system (imagine that). When the reboot resource runs it exits the Chef client with an exit code of 35. This code is considered a non-fatal code in Chef, but packer is picking that up as a failure and fails the whole build.
virtualbox-iso: * reboot[now] action reboot_now[2018-06-05T15:50:17-07:00] WARN: Rebooting system immediately, requested by 'now'
virtualbox-iso: [2018-06-05T15:50:17-07:00] WARN: Rebooting system immediately, requested by 'now'
virtualbox-iso:
virtualbox-iso:
virtualbox-iso: Running handlers:
virtualbox-iso: Running handlers complete
virtualbox-iso: Chef Client finished, 30/38 resources updated in 02 minutes 52 seconds
virtualbox-iso: [2018-06-05T15:50:17-07:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"Reboot by Chef", :timestamp=>2018-06-05 15:50:17 -0700, :requested_by=>"now"}
virtualbox-iso: [2018-06-05T15:50:17-07:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"Reboot by Chef", :timestamp=>2018-06-05 15:50:17 -0700, :requested_by=>"now"}
virtualbox-iso:
virtualbox-iso: Running handlers:
virtualbox-iso: [2018-06-05T15:50:17-07:00] ERROR: Running exception handlers
virtualbox-iso: [2018-06-05T15:50:17-07:00] ERROR: Running exception handlers
virtualbox-iso: Running handlers complete
virtualbox-iso: [2018-06-05T15:50:17-07:00] ERROR: Exception handlers complete
virtualbox-iso: [2018-06-05T15:50:17-07:00] ERROR: Exception handlers complete
virtualbox-iso: Chef Client failed. 30 resources updated in 02 minutes 52 seconds
virtualbox-iso: [2018-06-05T15:50:17-07:00] FATAL: Stacktrace dumped to c:/windows/temp/packer-chef-solo/local-mode-cache/cache/chef-stacktrace.out
virtualbox-iso: [2018-06-05T15:50:17-07:00] FATAL: Stacktrace dumped to c:/windows/temp/packer-chef-solo/local-mode-cache/cache/chef-stacktrace.out
virtualbox-iso: [2018-06-05T15:50:17-07:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
virtualbox-iso: [2018-06-05T15:50:17-07:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
virtualbox-iso: [2018-06-05T15:50:17-07:00] FATAL: Chef::Exceptions::Reboot: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"Reboot by Chef", :timestamp=>2018-06-05 15:50:17 -0700, :requested_by=>"now"}
virtualbox-iso: [2018-06-05T15:50:17-07:00] FATAL: Chef::Exceptions::Reboot: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"Reboot by Chef", :timestamp=>2018-06-05 15:50:17 -0700, :requested_by=>"now"}
==> virtualbox-iso: Deregistering and deleting VM...
==> virtualbox-iso: Deleting output directory...
Build 'virtualbox-iso' errored: Error executing Chef: Non-zero exit status: 35
==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: Error executing Chef: Non-zero exit status: 35
==> Builds finished but no artifacts were created.
@tas50 did you ever find a workaround for this issue?
String together Chef resources with a packer reboot resource in between. It鈥檚 clunky but it works
hi, I'm facing the same issue. Could someone provide a solution? I'm using Packer, AWS and Windows.
For anyone who is dealing with this issue, instead of having reboot in chef recipes, you will do reboot in Packer, and logically separate the recipes so that you can add reboot in the middle. Say you have a recipe that removed Windows Defender and after it we need to reboot then continue on the next recipe "default". This is how you can do it in your Packer json file under provisioners (sorry for formatting, it won't let me format well):
"provisioners": [
{
"type": "chef-solo",
"pause_before": "600s",
"install_command": "powershell.exe -Command \". { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; install\"",
"cookbook_paths": ["cookbooks"],
"chef_license": "accept",
"guest_os_type": "windows",
"run_list": [
"packer::remove_defender"
]
},
{
"type": "windows-restart"
},
{
"type": "chef-solo",
"pause_before": "600s",
"install_command": "powershell.exe -Command \". { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; install\"",
"cookbook_paths": ["cookbooks"],
"chef_license": "accept",
"guest_os_type": "windows",
"run_list": [
"packer::default"
]
},
{
"type": "windows-restart"
}
]
Most helpful comment
String together Chef resources with a packer reboot resource in between. It鈥檚 clunky but it works