我正在尝试使用packer.io构buildWindows AMI。
在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正在导致打包程序看到它没有成功运行。 我已经尝试使用-force
运行-force
,但是,这似乎不允许我成功地构build图像。
在这里我有点不知所措 – 我不确定是否最简单的方法是让我试图强迫打包者看到一个图像正在build立,或者试图在我的结尾添加另一个步骤打包器的powershell脚本试图强制该结果有一个很好的错误代码,并前进。
find这个问题,同时寻找一个回答我自己的问题,“封装器closures构build实例之前的sysprepping”,它给了我只是正确的线索来解决这个问题。
事实certificate,Packer的PowerShellconfiguration程序有一个可选的参数,叫做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脚本来进行查找和replace。
希望这可以帮助!
如果在目标计算机上启动了closures,我们已经看到最新的Packer二进制文件(0.10.1)中的实例,它将以类似的错误终止。
你应该只能看到args /generalize /oobe /quiet
,然后Packer会在产生AMI之前处理关机。