我正在尝试用packer.io构建Windows。
在powershell文件中,我运行了以下命令,作为供应步骤的最后一个命令:
Write-Host "Running the EC2Config.exe file to sysprep the image for UserData to run on next boot."
cmd.exe /c "C:\Program Files\Amazon\Ec2ConfigService\ec2config.exe" -sysprep在我的封隔器输出中,我看到了以下文本:
amazon-ebs: Running the EC2Config.exe file to sysprep the image for UserData to run on next boot.
amazon-ebs: Running in foreground...
amazon-ebs: SysprepUtils: Setting bundle/Sysprep operations for Vista/2008.
amazon-ebs: SysprepUtils: Reading Bundle Properties from C:\Program Files\Amazon\Ec2ConfigService\Settings\BundleConfig.xml
amazon-ebs: SysprepUtils: Processing property: AutoSysprep
amazon-ebs: SysprepUtils: Processing property: SetRDPCertificate
amazon-ebs: SysprepUtils: Changing plugin Ec2ConfigureRDP state to Disabled
amazon-ebs: SysprepUtils: Changing plugin Ec2OutputRDPCert state to Enabled
amazon-ebs: SysprepUtils: Processing property: SetPasswordAfterSysprep
amazon-ebs: SysprepUtils: Changing plugin Ec2SetPassword state to Enabled
amazon-ebs: SysprepUtils: Changing plugin Ec2WindowsActivate state to Enabled
amazon-ebs: SysprepUtils: Changing plugin Ec2HandleUserData state to Enabled
amazon-ebs: SysprepUtils: Changing plugin Ec2DynamicBootVolumeSize state to Enabled
amazon-ebs: SysprepUtils: Sysprep command: 'C:\windows\system32\sysprep\sysprep.exe'
amazon-ebs: SysprepUtils: Sysprep args: '"/unattend:C:\Program Files\Amazon\Ec2ConfigService\sysprep2008.xml" /oobe /shutdown /generalize'
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: No AMIs to cleanup
==> amazon-ebs: Deleting temporary keypair...
Build 'amazon-ebs' errored: Script exited with non-zero exit status: 1. Allowed exit codes are: [0]所以..。
它正在成功运行,然后运行sysprep,但是sysprep正导致packer看到它没有成功运行。我尝试过用-force运行packer,但是,这似乎不允许我成功地构建映像。
我有点不知所措--我不确定最简单的方法是强迫packer看到正在构建的图像,或者在powershell脚本的末尾为packer添加另一步,试图迫使它有一个很好的错误代码,然后继续前进。
发布于 2017-01-23 20:56:13
找到这个问题时,我自己的问题寻找一个答案‘在打包之前关闭构建实例’,它给了我正确的线索,以解决这个问题。
结果发现,Packer的PowerShell提供程序有一个可选的参数,称为valid_exit_codes。由于您看到的退出代码为1,请将valid_exit_codes设置为"0,1“。在你的封隔器windows.json中:
"valid_exit_codes": "0,1"
我不知道这有多新,我使用的是Packer 0.12.2。
有趣的是,我的ec2config.exe -sysprep运行结果为0:
amazon-ebs: SysprepUtils: Sysprep args: '"/unattend:C:\Program Files\Amazon\Ec2ConfigService\sysprep2008.xml" /oobe /shutdown /generalize'
2017/01/23 20:18:33 packer: 2017/01/23 20:18:33 [INFO] command 'powershell -executionpolicy bypass -encodedCommand aQBmACAAKAB ..deleted.. GUAcwB0AC0A=' exited with code: 0另一件您可能想考虑尝试的事情(由于时间的限制,我还没有):
从sysprep参数中移除/shutdown标志。您可以在C:\Program Files\Amazon\Ec2ConfigService\Settings\BundleConfig.xml中找到这一点。只需使用PowerShell脚本来查找和替换。
希望这能有所帮助!
发布于 2016-08-19 05:02:33
如果在目标机器中启动了关机,我们已经在最新的Packer二进制文件(0.10.1)上看到了一些实例,其中它将以类似的错误终止。
您应该能够只使用args /generalize /oobe /quiet,然后Packer将在它生成AMI之前处理关机。
https://serverfault.com/questions/797824
复制相似问题