3

When attempting to SysPrep an AWS Windows Server 2016 instance using Packer the following error is thrown:

Build 'amazon-ebs' errored: Script exited with non-zero exit status: 1. Allowed exit codes are: [0]

I'm calling the SysprepInstance.ps1 script as specified on http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2launch.html#ec2launch-sysprep.

Castrohenge
  • 422
  • 1
  • 7
  • 13

2 Answers2

4

Castrohenge's answer set me on the right path, but I preferred to pass the '-NoShutdown' switch to SysprepInstance.ps1 to accomplish the same goal.

C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SysprepInstance.ps1 -NoShutdown

Also keep in mind that features requiring restart can lock up sysprep and will fail to report back to packer. To solve that I simply use the 'restart' provisioner in packer before sysprep.

Ryan Meis
  • 56
  • 3
1

The issue was caused by the fact the SysprepInstance.ps1 script shutdown the instance, using the following command:

# Finally, perform sysprep.
Start-Process -FilePath $sysprepPath -ArgumentList ("/oobe /shutdown /generalize `"/unattend:{0}`"" -f $answerFilePath) -Wait -NoNewWindow

I resolved this by modifying the SysprepInstance.ps1 before running it, as follows:

$sysPrepInstanceFile = "C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SysprepInstance.ps1"

(Get-Content $sysPrepInstanceFile -Verbose).Replace("/shutdown ", "") | Set-Content $sysPrepInstanceFile -Verbose
Castrohenge
  • 422
  • 1
  • 7
  • 13