你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
适用于:✔️ Linux VM ✔️ 灵活规模集
使用本文排查和解决在使用 Azure VM 映像生成器时可能会遇到的常见问题。
VM 映像生成器失败可能发生在两个方面:
- 在提交映像模板期间
- 在生成映像期间
先决条件
以下是创建生成的先决条件:
VM 映像生成器服务使用 Windows 远程管理(WinRM)或安全外壳(SSH)与生成虚拟机(VM)通信。 请勿 在生成过程中禁用这些设置。
VM 映像生成器在生成过程中会在过渡资源组中创建资源。 资源的确切列表取决于映像模板指定的 网络配置 。 请务必验证 Azure Policy 不会阻止 VM 映像生成器创建或使用所需资源。
- 创建
IT_
资源组。 - 创建不带防火墙的存储帐户。
- 部署 Azure 容器实例。
- 部署 Azure 虚拟网络 资源(以及其中的子网)。
- 部署 Azure 专用终结点资源。
- 部署 Azure 文件存储。
- 创建
确保 Azure Policy 不会在生成 VM 或其他过渡资源(例如 Azure 扩展或标记修改)上安装意外功能。
确保 VM 映像生成器具有读取/写入映像和连接到存储帐户的正确权限。 有关详细信息,请查看适用于 Azure CLI 或 Azure PowerShell 的权限文档。
如果脚本或内联命令失败并出现错误(非零退出代码),则 VM 映像生成器会使生成失败。 确保已测试自定义脚本,并验证它们是否运行且没有错误(退出代码
0
)或需要用户输入。 有关详细信息,请参阅使用 VM 映像生成器和 PowerShell 创建 Azure 虚拟桌面映像。确保订阅有足够的 Azure 容器实例配额。
每次镜像构建可以在暂存资源组中最多部署一个临时 Azure 容器实例资源(具有四个标准核心)。 这些资源是独立映像生成所必需的。
注意
由 Internet 安全中心(CIS)管理的 Azure 市场上的 CIS 强化映像(Linux 或 Windows)可能会导致 VM 映像生成器服务由于配置而生成失败。 例如:
- 适用于 Windows 的 CIS 强化映像可能会中断 WinRM 连接,这是 VM 映像生成器生成的先决条件。
- 由于权限问题,适用于 Linux 的
chmod +x
CIS 强化映像可能会失败。
排查映像模板提交错误
映像模板提交错误只在提交时返回。 没有针对图像模板提交错误的错误日志。 如果在提交期间出现了错误,可通过检查模板的状态来返回该错误。 具体而言,审查 ProvisioningState
和 ProvisioningErrorMessage
/provisioningError
。
下面是 Azure CLI 的命令:
az image builder show --name $imageTemplateName --resource-group $imageResourceGroup
下面是 Azure PowerShell 的命令。 若要使用 Azure PowerShell,需要安装 VM 映像生成器 PowerShell 模块。
Get-AzImageBuilderTemplate -ImageTemplateName <imageTemplateName> -ResourceGroupName <imageTemplateResourceGroup> | Select-Object ProvisioningState, ProvisioningErrorMessage
下面是版本 2020-02-14 及更低版本的错误输出:
{
"code": "ValidationFailed",
"message": "Validation failed: 'ImageTemplate.properties.source': Field 'imageId' has a bad value: '/subscriptions/subscriptionID/resourceGroups/resourceGroupName/providers/Microsoft.Compute/images/imageName'. Please review http://aka.ms/azvmimagebuildertmplref for details on fields requirements in the Image Builder Template."
}
下面是版本 2021-10-01 及更高版本的错误输出:
{
"error": {
"code": "ValidationFailed",
"message": "Validation failed: 'ImageTemplate.properties.source': Field 'imageId' has a bad value: '/subscriptions/subscriptionID/resourceGroups/resourceGroupName/providers/Microsoft.Compute/images/imageName'. Please review http://aka.ms/azvmimagebuildertmplref for details on fields requirements in the Image Builder Template."
}
}
重要
API 版本 2021-10-01 引入了对错误架构的更改,该架构将成为每个未来 API 版本的一部分。 如果有任何 Azure VM 映像生成器自动化,请注意切换到 API 版本 2021-10-01 或更高版本时的新错误输出。
建议切换到最新的 API 版本后,不要还原到早期版本。 如果还原,则必须再次更改自动化,以生成早期的错误架构。 我们预计将来的版本不会再次更改错误架构。
以下部分提供常见映像模板提交错误的问题解决指南。
目前不支持更新或升级映像模板
错误
'Conflict'. Details: Update/Upgrade of image templates is currently not supported
原因
模板已存在。
解决方案
如果提交映像配置模板,并且提交失败,那么,失败的模板项目仍然会存在。 请删除该失败的模板。
无法在映像模板上使用分配的托管标识
错误
The assigned managed identity cannot be used. Please remove the existing one and re-assign a new identity. For more troubleshooting steps go to https://aka.ms/azvmimagebuilderts.
原因
在某些情况下,无法使用创建的分配给映像模板的托管标识。
一个可能的原因是 VM 映像生成器模板使用客户提供的临时资源组,在删除映像模板之前会删除托管标识。 (暂存资源组就是这种情形。)
解决方案
使用 Azure CLI 重置映像模板上的托管标识。 请务必将 Azure CLI 更新 到 2.45.0 版本或更高版本。
从目标 VM 映像生成器模板中确认托管标识:
az image builder identity show -g <template resource group> -n <template name>
从目标 VM 映像生成器模板中删除托管标识:
az image builder identity remove -g <template resource group> -n <template name> --user-assigned <identity resource id>
将新标识分配给目标 VM 映像生成器模板:
az image builder identity assign -g <template rg> -n <template name> --user-assigned <identity resource id>
有关配置权限的详细信息,请参阅使用 Azure CLI 配置 VM 映像生成器服务权限或使用 PowerShell 配置 VM 映像生成器服务权限。
分配的托管标识无权访问资源
错误
Not authorized to access the resource: <resource-not-able-to-access>. Please check the user assigned identity has the correct permissions. For more details, go to https://aka.ms/azvmimagebuilderts.
原因
创建的分配给映像模板的托管标识缺少访问错误消息中提到的共享资源的全部权限。
解决方案
从目标 VM 映像生成器模板中确认托管标识:
az image builder identity show -g <template resource group> -n <template name>
查看标识的角色分配:
az role assignment list --assignee <identity_client_id_or_principal_id>
分配所需的角色。 必要时,请创建具有所需权限的角色。
有关配置权限的详细信息,请参阅使用 Azure CLI 配置 VM 映像生成器服务权限或使用 PowerShell 配置 VM 映像生成器服务权限。
资源操作已完成,终端预配状态为“失败”
错误
Microsoft.VirtualMachineImages/imageTemplates 'helloImageTemplateforSIG01' failed with message '{
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"message": "The resource operation completed with terminal provisioning state 'Failed'.",
"details": [
{
"code": "InternalOperationError",
"message": "Internal error occurred."
原因
在大多数情况下,发生资源部署失败错误是由于缺少权限。 与暂存资源组冲突可能也会引起此错误。
解决方案
根据场景的不同,VM 映像生成器可能会需要以下位置的权限:
- 源映像或 Azure Compute Gallery(前称为共享映像库)资源组。
- 分发映像或 Azure Compute Gallery 资源。
File
定制器访问的存储帐户、容器或 Blob。
此外,请确保为每个映像模板唯一指定暂存资源组名称。
有关配置权限的详细信息,请参阅使用 Azure CLI 配置 VM 映像生成器服务权限或使用 PowerShell 配置 VM 映像生成器服务权限。
获取托管映像时出错
错误
Build (Managed Image) step failed: Error getting Managed Image '/subscriptions/.../providers/Microsoft.Compute/images/mymanagedmg1': Error getting managed image (...): compute.
ImagesClient#Get: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error.
Status=403 Code="AuthorizationFailed" Message="The client '......' with object id '......' doesn't have authorization to perform action 'Microsoft.Compute/images/read' over scope
原因
权限缺失。
解决方案
根据场景的不同,VM 映像生成器可能会需要以下位置的权限:
- 源映像或 Azure Compute Gallery 资源组。
- 分发映像或 Azure Compute Gallery 资源。
File
定制器访问的存储帐户、容器或 Blob。
有关配置权限的详细信息,请参阅使用 Azure CLI 配置 VM 映像生成器服务权限或使用 PowerShell 配置 VM 映像生成器服务权限。
映像版本的生成步骤失败
错误
Build (Shared Image Version) step failed for Image Version '/subscriptions/.../providers/Microsoft.Compute/galleries/.../images/... /versions/0.23768.4001': Error getting Image Version '/subscriptions/.../resourceGroups/<rgName>/providers/Microsoft.Compute/galleries/.../images/.../versions/0.23768.4001': Error getting image version '... :0.23768.4001': compute.GalleryImageVersionsClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error.
Status=404 Code="ResourceNotFound" Message="The Resource 'Microsoft.Compute/galleries/.../images/.../versions/0.23768.4001' under resource group '<rgName>' was not found."
原因
VM 映像生成器找不到源映像。
解决方案
请确保源映像正确并且存在于 VM 映像生成器的位置。
将外部文件下载到本地文件时出错
错误
Downloading external file (<myFile>) to local file (xxxxx.0.customizer.fp) [attempt 1 of 10] failed: Error downloading '<myFile>' to 'xxxxx.0.customizer.fp'..
原因
文件名或位置不正确,或无法访问该位置。
解决方案
确保可以访问该文件。 验证名称和位置是否正确。
某些文件存储库可能使用不受支持的密码套件,并导致 VM 映像生成器的下载错误。 将文件和脚本存储在 Azure 存储帐户中,以帮助确保安全密码套件,并使 VM 映像生成器能够访问这些文件和脚本。 有关如何在 Azure 存储帐户中存储文件的详细信息,请参阅 存储帐户概述。
创建磁盘时发生授权错误
VM 映像生成器生成失败,并出现如下示例所示的授权错误。
错误
Attempting to deploy created Image template in Azure fails with an 'The client '6df325020-fe22-4e39-bd69-10873965ac04' with object id '6df325020-fe22-4e39-bd69-10873965ac04' does not have authorization to perform action 'Microsoft.Compute/disks/write' over scope '/subscriptions/<subscriptionID>/resourceGroups/<resourceGroupName>/providers/Microsoft.Compute/disks/proxyVmDiskWin_<timestamp>' or the scope is invalid. If access was recently granted, please refresh your credentials.'
原因
尝试使用 Windows 源映像指定 VM 映像生成器服务的预先存在的资源组和虚拟网络时,会发生此错误。
解决方案
需要将参与者角色分配给与 VM 映像生成器第一方应用相对应的服务主体的资源组。 使用以下 Azure CLI 命令或 Azure 门户说明。
首先,使用以下 Azure CLI 命令验证服务主体是否与 VM 映像生成器第一方应用相关联:
az ad sp show --id {servicePrincipalName, or objectId}
然后,若要使用 Azure CLI 实现此解决方案,请使用以下命令:
az role assignment create -g {ResourceGroupName} --assignee {AibrpSpOid} --role Contributor
若要在门户中实现此解决方案,请按照 使用 Azure 门户分配 Azure 角色中的说明作:
对于 步骤 1:确定所需的范围,所需的范围是你的资源组。
对于 步骤 3:选择适当的角色,角色为“参与者”。
对于 步骤 4:选择需要访问权限的人员,请选择 Azure 虚拟机映像生成器 成员。
在 步骤 7:分配角色时,可以分配角色。
排查生成故障
对于映像构建失败,请先从lastRunStatus
获取错误信息,然后查看customization.log
文件中的详细信息。
az image builder show --name $imageTemplateName --resource-group $imageResourceGroup
Get-AzImageBuilderTemplate -ImageTemplateName <imageTemplateName> -ResourceGroupName <imageTemplateResourceGroup> | Select-Object LastRunStatus, LastRunStatusMessage
自定义日志
在映像生成期间访问实时日志
若要有效监视映像生成进度,可以访问 VM 映像生成器在 Azure 容器实例中生成的实时日志。 这些日志提供对生成过程的实时见解。 它们可帮助你识别任何问题,或确认生成按预期进行。
若要查找和查看实时日志,请执行以下作:
启动映像生成过程。
转到 Azure 门户并选择 “资源组”。 按启动映像生成的订阅进行筛选。
查找并选择与镜像构建关联的暂存资源组。 此资源组包含 VM 映像生成器服务的生成资源。 有关暂存资源组的详细信息,请参阅属性:stagingResourceGroup。
在此资源组中,查找名为
vmimagebuilder-build-container-**********
的资源。 如果它不可见,请等待几分钟并刷新页面。在左窗格中的 “设置”下,选择“ 容器”。
转到“ 日志 ”选项卡,在映像生成过程中查看实时日志。
如果未看到任何日志,请尝试在几分钟后刷新容器。
在映像生成后下载自定义和/或验证日志
映像生成完成后,自定义日志和验证日志存储在 VM 映像生成器服务创建的过渡资源组中的存储帐户中的容器中。 有关暂存资源组的详细信息,请参阅属性:stagingResourceGroup。
若要查找并下载customization.log
文件或validation.log
文件,请执行以下步骤:
在 Azure 门户中,通过筛选 VM 映像生成器服务创建的过渡资源组中的存储帐户,转到相关的存储帐户。
在存储帐户下,转到 数据存储。
选择 “容器 ”选项,然后选择
packerlogs
容器。如果映像构建多次运行,在
packerlogs
容器内将会出现多个文件夹。 这些文件夹按照从最早版本到最新版本的顺序排列。 选择对应您感兴趣的版本的文件夹。在所选文件夹中,选择
customization.log
和/或validation.log
文件,然后选择 “下载 ”以下载其内容。
自定义日志的各个阶段
该日志为详细的日志。 其中涉及映像生成,包括映像分发方面(如 Azure Compute Gallery 复制)的任何问题。 这些问题显示在图像模板状态的错误消息中。
customization.log
文件包括以下阶段:
使用 Azure 资源管理器模板将生成 VM 和依赖项部署到
IT_
过渡资源组。 此阶段包括对 VM 映像生成器资源提供程序的多个POST
请求:Azure request method="POST" request="https://management.azure.com/subscriptions/<subID>/resourceGroups/IT_aibImageRG200_window2019VnetTemplate01_dec33089-1cc3-cccc-cccc-ccccccc/providers/Microsoft.Storage/storageAccounts .. PACKER OUT ==> azure-arm: Deploying deployment template ... ..
获取部署的状态。 此阶段包括每个资源部署的状态:
PACKER ERR 2020/04/30 23:28:50 packer: 2020/04/30 23:28:50 Azure request method="GET" request="https://management.azure.com/subscriptions/<subID>/resourcegroups/IT_aibImageRG200_window2019VnetTemplate01_dec33089-1cc3-4505-ae28-6661e43fac48/providers/Microsoft.Resources/deployments/pkrdp51lc0339jg/operationStatuses/08586133176207523519?[REDACTED]" body=""
连接到生成 VM。
在 Windows 中,VM 映像生成器使用 WinRM 进行连接:
PACKER ERR 2020/04/30 23:30:50 packer: 2020/04/30 23:30:50 Waiting for WinRM, up to timeout: 10m0s .. PACKER OUT azure-arm: WinRM connected.
在 Linux 中,VM 映像生成器使用 SSH 进行连接:
PACKER OUT ==> azure-arm: Waiting for SSH to become available... PACKER ERR 2019/12/10 17:20:51 packer: 2020/04/10 17:20:51 [INFO] Waiting for SSH, up to timeout: 20m0s PACKER OUT ==> azure-arm: Connected to SSH!
运行自定义。 自定义项运行时,可以通过查看
customization.log
文件来标识它们。 搜索(telemetry)
:(telemetry) Starting provisioner windows-update (telemetry) ending windows-update (telemetry) Starting provisioner powershell (telemetry) ending powershell (telemetry) Starting provisioner file (telemetry) ending file (telemetry) Starting provisioner windows-restart (telemetry) ending windows-restart (telemetry) Finalizing. - This means the build has finished
撤销。 VM 映像生成器会添加一个隐藏的定制器。 此步骤负责为撤销准备 VM。 在 Windows 中,它运行
Sysprep
(通过使用c:\DeprovisioningScript.ps1
)。 在 Linux 中,它运行waagent-deprovision
(通过使用/tmp/DeprovisioningScript.sh
)。例如:
PACKER ERR 2020/03/04 23:05:04 [INFO] (telemetry) Starting provisioner powershell PACKER ERR 2020/03/04 23:05:04 packer: 2020/03/04 23:05:04 Found command: if( TEST-PATH c:\DeprovisioningScript.ps1 ){cat c:\DeprovisioningScript.ps1} else {echo "Deprovisioning script [c:\DeprovisioningScript.ps1] could not be found. Image build may fail or the VM created from the Image may not boot. Please make sure the deprovisioning script is not accidentally deleted by a Customizer in the Template."}
清理。 生成完成后,将删除 VM 映像生成器资源:
PACKER ERR ==> azure-arm: Deleting individual resources ... ... PACKER ERR 2020/02/04 02:04:23 packer: 2020/02/04 02:04:23 Azure request method="DELETE" request="https://management.azure.com/subscriptions/<subId>/resourceGroups/IT_aibDevOpsImg_t_vvvvvvv_yyyyyy-de5f-4f7c-92f2-xxxxxxxx/providers/Microsoft.Network/networkInterfaces/pkrnijamvpo08eo?[REDACTED]" body="" ... PACKER ERR ==> azure-arm: The resource group was not created by Packer, not deleting ...
排查脚本或内联自定义问题
以下提示可帮助你排查脚本或内联自定义问题:
- 在将代码提供给 VM 映像生成器之前先测试代码。
- 确保 Azure Policy 和 Azure 防火墙允许连接到远程资源。
- 使用
Write-Host
或echo
将输出信息发送到控制台。 这样做可以搜索customization.log
文件。
排查常见构建错误
由于策略冲突,模板部署失败
错误
{
"statusCode": "BadRequest",
"serviceRequestId": null,
"statusMessage": "{\"error\":{\"code\":\"InvalidTemplateDeployment\",\"message\":\"The template deployment failed because of policy violation. Please see details for more information.\",\"details\":[{\"code\":\"RequestDisallowedByPolicy\",\"target\":\"<target_name>\",\"message\":\"Resource '<resource_name>' was disallowed by policy. Policy identifiers: '[{\\\"policyAssignment\\\":{\\\"name\\\":\\\"[Initiative] KeyVault (Microsoft.KeyVault)\\\",\\\"id\\\":\\\"/providers/Microsoft.Management/managementGroups/<managementGroup_name>/providers/Microsoft.Authorization/policyAssignments/Microsoft.KeyVault\\\"},\\\"policyDefinition\\\":{\\\"name\\\":\\\"Azure Key Vault should disable public network access\\\",\\\"id\\\":\\\"/providers/Microsoft.Management/managementGroups/<managementGroup_name>/providers/Microsoft.Authorization/policyDefinitions/KeyVault.disablePublicNetworkAccess_deny_deny\\\"},\\\"policySetDefinition\\\":{\\\"name\\\":\\\"[Initiative] KeyVault (Microsoft.KeyVault)\\\",\\\"id\\\":\\\"/providers/Microsoft.Management/managementGroups/<managementGroup_name>/providers/Microsoft.Authorization/policySetDefinitions/Microsoft.KeyVault\\\"}}]'.\",\"additionalInfo\":[{\"type\":\"PolicyViolation\"}]}]}}",
"eventCategory": "Administrative",
"entity": "/subscriptions/<subscription_ID>/<resourcegroups>/<resourcegroupname>/providers/Microsoft.Resources/deployments/<deployment_name>",
"message": "Microsoft.Resources/deployments/validate/action",
"hierarchy": "<subscription_ID>/<resourcegroupname>/<policy_name>/<managementGroup_name>/<deployment_ID>"
}
原因
上述策略冲突错误是使用禁用公共访问的 Azure 密钥保管库的结果。 目前,VM 映像生成器不支持此配置。
解决方案
必须创建启用了公共访问的密钥保管库。
Packer 生成命令失败
错误
"provisioningState": "Succeeded",
"lastRunStatus": {
"startTime": "2020-04-30T23:24:06.756985789Z",
"endTime": "2020-04-30T23:39:14.268729811Z",
"runState": "Failed",
"message": "Failed while waiting for packerizer: Microservice has failed: Failed while processing request: Error when executing packerizer: Packer build command has failed: exit status 1. During the image build, a failure has occurred, please review the build log to identify which build/customization step failed. For more troubleshooting steps go to https://aka.ms/azvmimagebuilderts. Image Build log ___location: https://xxxxxxxxxx.blob.core.windows.net/packerlogs/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/customization.log. OperationId: xxxxxx-5a8c-4379-xxxx-8d85493bc791. Use this operationId to search packer logs."
原因
packer 生成命令失败是定制化故障。
解决方案
查看日志以查找定制器失败。 搜索 (telemetry)
。
例如:
(telemetry) Starting provisioner windows-update
(telemetry) ending windows-update
(telemetry) Starting provisioner powershell
(telemetry) ending powershell
(telemetry) Starting provisioner file
(telemetry) ending file
(telemetry) Starting provisioner windows-restart
(telemetry) ending windows-restart
(telemetry) Finalizing. - This means the build has finished
部署因超时而失败
错误
Deployment failed. Correlation ID: xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx. Failed in building/customizing image: Failed while waiting for packerizer: Timeout waiting for microservice to complete: 'context deadline exceeded'
原因
生成超出了超时。 lastRunStatus
中出现此错误。
解决方案
查看
customization.log
文件。 标识要运行的最后一个定制器。 从日志底部开始搜索(telemetry)
。检查脚本的自定义设置。 自定义可能不会抑制用户对命令的交互,例如
quiet
选项。 例如,apt-get install -y
会导致脚本执行等待用户交互。如果使用
File
定制器下载大于 20 MB 的项目,请参阅解决方法部分。查看脚本中可能导致等待状态的错误和依赖项。
如果预计自定义项需要更多的时间,请增加值
buildTimeoutInMinutes
。 默认值为 4 小时。如果有资源密集型作(例如下载千兆字节的文件),请考虑基础生成 VM 的大小。
该服务会使用 Standard_D1_v2 VM。 VM 有一个 vCPU 和 3.5 GB 内存。 如果要下载 50 GB,可能会耗尽 VM 资源,并导致 VM 映像生成器与生成 VM 之间发生通信故障。 设置
VM_size
以使用内存更大的虚拟机重新尝试构建。
文件下载时间长
错误
[086cf9c4-0457-4e8f-bfd4-908cfe3fe43c] PACKER OUT
myBigFile.zip 826 B / 826000 B 1.00%
[086cf9c4-0457-4e8f-bfd4-908cfe3fe43c] PACKER OUT
myBigFile.zip 1652 B / 826000 B 2.00%
[086cf9c4-0457-4e8f-bfd4-908cfe3fe43c] PACKER OUT
..
hours later...
..
myBigFile.zip 826000 B / 826000 B 100.00%
[086cf9c4-0457-4e8f-bfd4-908cfe3fe43c] PACKER OUT
原因
File
自定义工具正在下载大型文件。
解决方案
File
定制器仅适用于小型(小于 20 MB)的文件下载。 如果要下载更大的文件,请使用脚本或内联命令。 例如,在 Linux 中,可以使用 wget
或 curl
。 在 Windows 中可以使用 Invoke-WebRequest
。
Windows 重启持续失败,错误代码为 1190
错误
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 [INFO] (telemetry) Starting provisioner windows-restart
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-plugin-azure plugin: 2023/06/13 08:28:58 [INFO] starting remote command: shutdown /r /f /t 10
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-plugin-azure plugin: 2023/06/13 08:28:58 [INFO] command 'shutdown /r /f /t 10' exited with code: 0
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER OUT ==> azure-arm: A system shutdown has already been scheduled.(1190)
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-plugin-azure plugin: 2023/06/13 08:28:58 [INFO] RPC endpoint: Communicator ended with: 0
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 [INFO] 0 bytes written for 'stdout'
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 [INFO] 0 bytes written for 'stderr'
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 [INFO] RPC client: Communicator ended with: 0
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 [INFO] RPC endpoint: Communicator ended with: 0
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-provisioner-windows-restart plugin: [INFO] 0 bytes written for 'stdout'
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-provisioner-windows-restart plugin: [INFO] 0 bytes written for 'stderr'
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-provisioner-windows-restart plugin: [INFO] RPC client: Communicator ended with: 0
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-provisioner-windows-restart plugin: Check if machine is rebooting...
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-plugin-azure plugin: 2023/06/13 08:28:58 [INFO] starting remote command: shutdown /r /f /t 60 /c "packer restart test"
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-plugin-azure plugin: 2023/06/13 08:28:58 [INFO] command 'shutdown /r /f /t 60 /c "packer restart test"' exited with code: 1190
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-plugin-azure plugin: 2023/06/13 08:28:58 [INFO] RPC endpoint: Communicator ended with: 1190
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 [INFO] 52 bytes written for 'stderr'
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 [INFO] 0 bytes written for 'stdout'
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 [INFO] RPC client: Communicator ended with: 1190
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 [INFO] RPC endpoint: Communicator ended with: 1190
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-provisioner-windows-restart plugin: [INFO] 52 bytes written for 'stderr'
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-provisioner-windows-restart plugin: [INFO] 0 bytes written for 'stdout'
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-provisioner-windows-restart plugin: [INFO] RPC client: Communicator ended with: 1190
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:28:58 packer-provisioner-windows-restart plugin: Reboot already in progress, waiting...
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:29:08 packer-provisioner-windows-restart plugin: Check if machine is rebooting...
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:29:09 [INFO] 0 bytes written for 'stderr'
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:29:09 packer-provisioner-windows-restart plugin: [INFO] 0 bytes written for 'stderr'
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:29:09 packer-provisioner-windows-restart plugin: Waiting for machine to reboot with timeout: 15m0s
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:29:09 packer-provisioner-windows-restart plugin: Waiting for machine to become available...
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER OUT ==> Some builds didn't complete successfully and had errors:
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:46:26 machine readable: azure-arm,error []string{"Timeout waiting for machine to restart."}
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER OUT --> azure-arm: Timeout waiting for machine to restart.
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR ==> Builds finished but no artifacts were created.
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER OUT
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER ERR 2023/06/13 08:46:26 [INFO] (telemetry) Finalizing.
[864c0337-b300-48ab-8e8e-7894bc695b7c] PACKER OUT ==> Builds finished but no artifacts were created.
原因
在基于 Windows Server 2016 的映像中,Windows 更新步骤被过早设定。
解决方案
将 restartTimeout
从 15 分钟延长到 30 分钟。
等待 Azure Compute Gallery 时发生错误
错误
Deployment failed. Correlation ID: XXXXXX-XXXX-XXXXXX-XXXX-XXXXXX. Failed in distributing 1 images out of total 1: {[Error 0] [Distribute 0] Error publishing MDI to Azure Compute Gallery:/subscriptions/<subId>/resourceGroups/xxxxxx/providers/Microsoft.Compute/galleries/xxxxx/images/xxxxxx, Location:eastus. Error: Error returned from SIG client while publishing MDI to Azure Compute Gallery for dstImageLocation: eastus, dstSubscription: <subId>, dstResourceGroupName: XXXXXX, dstGalleryName: XXXXXX, dstGalleryImageName: XXXXXX. Error: Error waiting on Azure Compute Gallery future for resource group: XXXXXX, gallery name: XXXXXX, gallery image name: XXXXXX.Error: Future#WaitForCompletion: context has been cancelled: StatusCode=200 -- Original Error: context deadline exceeded}
原因
VM 映像生成器在等待添加映像并将其复制到 Azure Compute Gallery 时超时。
如果将该映像注入到库中,则可以假定该映像生成已成功。 但是,由于 VM 映像生成器正在等待 Azure 计算库完成复制,因此整个过程失败。
即使生成失败,复制也会继续。 可以通过检查发行版runOutput
来获取镜像版本的属性。
$runOutputName=<distributionRunOutput>
az resource show \
--ids "/subscriptions/$subscriptionID/resourcegroups/$imageResourceGroup/providers/Microsoft.VirtualMachineImages/imageTemplates/$imageTemplateName/runOutputs/$runOutputName" \
--api-version=2020-02-14
解决方案
增加 buildTimeoutInMinutes
的值。
信息事件显示 Windows 资源不足
错误
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT azure-arm: Waiting for operation to complete (system performance: 1% cpu; 37% memory)...
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT azure-arm: Waiting for operation to complete (system performance: 51% cpu; 35% memory)...
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT azure-arm: Waiting for operation to complete (system performance: 21% cpu; 37% memory)...
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT azure-arm: Waiting for operation to complete (system performance: 21% cpu; 36% memory)...
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT azure-arm: Waiting for operation to complete (system performance: 90% cpu; 32% memory)...
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT azure-arm: Waiting for the Windows Modules Installer to exit...
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer: 2020/04/30 23:38:58 [INFO] command 'PowerShell -ExecutionPolicy Bypass -OutputFormat Text -File C:/Windows/Temp/packer-windows-update-elevated.ps1' exited with code: 101
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT ==> azure-arm: Restarting the machine...
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer: 2020/04/30 23:38:58 [INFO] RPC endpoint: Communicator ended with: 101
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 [INFO] 1672 bytes written for 'stdout'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 [INFO] 0 bytes written for 'stderr'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 [INFO] RPC client: Communicator ended with: 101
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 [INFO] RPC endpoint: Communicator ended with: 101
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT ==> azure-arm: Waiting for machine to become available...
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer-provisioner-windows-update: 2020/04/30 23:38:58 [INFO] 1672 bytes written for 'stdout'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer-provisioner-windows-update: 2020/04/30 23:38:58 [INFO] 0 bytes written for 'stderr'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer-provisioner-windows-update: 2020/04/30 23:38:58 [INFO] RPC client: Communicator ended with: 101
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer: 2020/04/30 23:38:58 [INFO] starting remote command: shutdown.exe -f -r -t 0 -c "packer restart"
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer: 2020/04/30 23:38:58 [INFO] command 'shutdown.exe -f -r -t 0 -c "packer restart"' exited with code: 0
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer: 2020/04/30 23:38:58 [INFO] RPC endpoint: Communicator ended with: 0
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 [INFO] 0 bytes written for 'stderr'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 [INFO] 0 bytes written for 'stdout'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT ==> azure-arm: A system shutdown is in progress.(1115)
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 [INFO] RPC client: Communicator ended with: 0
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 [INFO] RPC endpoint: Communicator ended with: 0
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer-provisioner-windows-update: 2020/04/30 23:38:58 [INFO] 0 bytes written for 'stdout'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer-provisioner-windows-update: 2020/04/30 23:38:58 [INFO] 0 bytes written for 'stderr'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:58 packer-provisioner-windows-update: 2020/04/30 23:38:58 [INFO] RPC client: Communicator ended with: 0
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 packer: 2020/04/30 23:38:59 [INFO] starting remote command: shutdown.exe -f -r -t 60 -c "packer restart test"
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 packer: 2020/04/30 23:38:59 [INFO] command 'shutdown.exe -f -r -t 60 -c "packer restart test"' exited with code: 1115
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 packer: 2020/04/30 23:38:59 [INFO] RPC endpoint: Communicator ended with: 1115
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 [INFO] 0 bytes written for 'stdout'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 [INFO] 40 bytes written for 'stderr'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 [INFO] RPC client: Communicator ended with: 1115
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 [INFO] RPC endpoint: Communicator ended with: 1115
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 packer-provisioner-windows-update: 2020/04/30 23:38:59 [INFO] 40 bytes written for 'stderr'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 packer-provisioner-windows-update: 2020/04/30 23:38:59 [INFO] 0 bytes written for 'stdout'
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 packer-provisioner-windows-update: 2020/04/30 23:38:59 [INFO] RPC client: Communicator ended with: 1115
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER ERR 2020/04/30 23:38:59 packer-provisioner-windows-update: 2020/04/30 23:38:59 Retryable error: Machine not yet available (exit status 1115)
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT Build 'azure-arm' errored: unexpected EOF
[45f485cf-5a8c-4379-9937-8d85493bc791] PACKER OUT
原因
原因是资源耗尽。 当 Windows 更新使用默认生成 VM 大小运行(D1_V2)时,通常会发生此问题。
解决方案
增加构建 VM 的大小。
生成已完成,但未创建任何项目
警告
[<log_id>] PACKER 2023/09/14 19:01:18 ui: Build 'azure-arm' finished after 3 minutes 13 seconds.
[<log_id>] PACKER 2023/09/14 19:01:18 ui:
[<log_id>] PACKER ==> Wait completed after 3 minutes 13 seconds
[<log_id>] PACKER 2023/09/14 19:01:18 ui:
[<log_id>] PACKER ==> Builds finished but no artifacts were created.
[<log_id>] PACKER 2023/09/14 19:01:18 [INFO] (telemetry) Finalizing.
[<log_id>] PACKER 2023/09/14 19:01:19 waiting for all plugin processes to complete...
[<log_id>] PACKER 2023/09/14 19:01:19 /aib/packerInput/packer-plugin-azure: plugin process exited
[<log_id>] PACKER 2023/09/14 19:01:19 /aib/packerInput/packer: plugin process exited
[<log_id>] PACKER 2023/09/14 19:01:19 /aib/packerInput/packer: plugin process exited
[<log_id>] PACKER 2023/09/14 19:01:19 /aib/packerInput/packer: plugin process exited
[<log_id>] PACKER Done exporting Packer logs to Azure Storage.
解决方案
可以安全地忽略上述警告。
跳过了映像创建
警告
[<log_id>] PACKER 2023/09/14 19:00:18 ui: ==> azure-arm: -> Snapshot ID : '/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_name>/providers/Microsoft.Compute/snapshots/<snapshot_name>'
[<log_id>] PACKER 2023/09/14 19:00:18 ui: ==> azure-arm: Skipping image creation...
[<log_id>] PACKER 2023/09/14 19:00:18 ui: ==> azure-arm:
[<log_id>] PACKER ==> azure-arm: Deleting individual resources ...
[<log_id>] PACKER 2023/09/14 19:00:18 packer-plugin-azure plugin: 202
解决方案
可以安全地忽略上述警告。
找不到资源
错误
"provisioningState": "Succeeded",
"lastRunStatus": {
"startTime": "2020-05-01T00:13:52.599326198Z",
"endTime": "2020-05-01T00:15:13.62366898Z",
"runState": "Failed",
"message": "network.InterfacesClient#UpdateTags: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code=\"ResourceNotFound\" Message=\"The Resource 'Microsoft.Network/networkInterfaces/aibpls7lz2e.nic.4609d697-be0a-4cb0-86af-49b6fe877fe1' under resource group 'IT_aibImageRG200_window2019VnetTemplate01_9988723b-af56-413a-9006-84130af0e9df' was not found.\""
},
原因
权限缺失。
解决方案
重新检查 VM 映像生成器是否具有它所需的所有权限。
有关配置权限的详细信息,请参阅使用 Azure CLI 配置 VM 映像生成器服务权限或使用 PowerShell 配置 VM 映像生成器服务权限。
存在 Sysprep 计时问题
错误
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: Write-Output '>>> Waiting for GA Service (RdAgent) to start ...'
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: while ((Get-Service RdAgent) -and ((Get-Service RdAgent).Status -ne 'Running')) { Start-Sleep -s 5 }
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: Write-Output '>>> Waiting for GA Service (WindowsAzureTelemetryService) to start ...'
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: while ((Get-Service WindowsAzureTelemetryService) -and ((Get-Service WindowsAzureTelemetryService).Status -ne 'Running')) { Start-Sleep -s 5 }
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: Write-Output '>>> Waiting for GA Service (WindowsAzureGuestAgent) to start ...'
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: while ((Get-Service WindowsAzureGuestAgent) -and ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running')) { Start-Sleep -s 5 }
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: Write-Output '>>> Sysprepping VM ...'
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: if( Test-Path $Env:SystemRoot\system32\Sysprep\unattend.xml ) {
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: Remove-Item $Env:SystemRoot\system32\Sysprep\unattend.xml -Force
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: }
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: & $Env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /quiet /quit
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: while($true) {
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: $imageState = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State).ImageState
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: Write-Output $imageState
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: if ($imageState -eq 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { break }
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: Start-Sleep -s 5
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: }
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: Write-Output '>>> Sysprep complete ...'
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: >>> Waiting for GA Service (RdAgent) to start ...
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: >>> Waiting for GA Service (WindowsAzureTelemetryService) to start ...
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: >>> Waiting for GA Service (WindowsAzureGuestAgent) to start ...
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: >>> Sysprepping VM ...
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_COMPLETE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT ==> azure-arm: Get-Service : Cannot find any service with service name 'WindowsAzureGuestAgent'.
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT ==> azure-arm: At C:\DeprovisioningScript.ps1:6 char:9
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT ==> azure-arm: + while ((Get-Service WindowsAzureGuestAgent) -and ((Get-Service Window ...
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT ==> azure-arm: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT ==> azure-arm: + CategoryInfo : ObjectNotFound: (WindowsAzureGuestAgent:String) [Get-Service], ServiceCommandException
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT ==> azure-arm: + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT ==> azure-arm:
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
...
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT azure-arm: IMAGE_STATE_UNDEPLOYABLE
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER ERR 2020/05/05 22:26:17 Cancelling builder after context cancellation context canceled
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT Cancelling build after receiving terminated
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER ERR 2020/05/05 22:26:17 packer: 2020/05/05 22:26:17 Cancelling provisioning due to context cancellation: context canceled
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT ==> azure-arm:
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER ERR 2020/05/05 22:26:17 packer: 2020/05/05 22:26:17 Cancelling hook after context cancellation context canceled
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER OUT ==> azure-arm: The resource group was not created by Packer, deleting individual resources ...
[922bdf36-b53c-4e78-9cd8-6b70b9674685] PACKER ERR ==> azure-arm: The resource group was not created by Packer, deleting individual resources ...
原因
D1_V2 VM 大小可能是计时问题的原因。 如果自定义项受到限制,并且运行时间不到三秒,则 VM 映像生成器将运行 Sysprep
命令以取消预配。 当 VM 映像生成器撤销时,Sysprep
命令会检查 WindowsAzureGuestAgent
,该代理可能未完全安装,因而可能会导致计时问题。
解决方案
若要避免计时问题,可以增加 VM 大小或添加 60 秒 PowerShell 睡眠自定义。
Azure 容器实例提供程序未注册
错误
Azure Container Instances provider not registered for your subscription.
原因
模板订阅未注册 Azure 容器实例提供程序。
解决方案
为模板订阅注册 Azure 容器实例提供程序,并添加以下命令之一:
- Azure CLI:
az provider register -n Microsoft.ContainerInstance
- Azure PowerShell:
Register-AzResourceProvider -ProviderNamespace Microsoft.ContainerInstance
订阅已超过 Azure 容器实例配额
错误
Azure Container Instances quota exceeded
原因
订阅没有足够的 Azure 容器实例配额,VM 映像生成器无法成功生成映像。
解决方案
您可以执行以下操作,使 Azure 容器实例配额用于 VM 映像生成器:
在订阅中查找 Azure 容器实例的其他使用情况。 删除任何不需要的实例,使配额可用于 VM 映像生成器。
VM 映像生成器仅在生成过程中临时部署 Azure 容器实例。 生成完成后,将删除这些实例。
如果订阅中运行的并发映像生成过多,可以考虑延迟某些映像生成。 此延迟可减少订阅中 Azure 容器实例的并发使用率。
如果映像模板是通过触发器为自动映像生成设置的,则 VM 映像生成器会自动重试此类失败的生成。
如果订阅的当前 Azure 容器实例限制太低,无法支持映像生成方案,则可以 请求增加 Azure 容器实例配额。
注意
独立映像生成需要 Azure 容器实例资源。
在一段时间内部署了过多的 Azure 容器实例资源
错误
“在一段时间内部署的 Azure 容器实例太多。
原因
订阅没有足够的 Azure 容器实例配额,VM 映像生成器无法同时成功生成映像。
解决方案
可以尝试以下解决方案:
- 以更低的并发性重试失败的生成。
- 如果订阅的当前 Azure 容器实例限制太低,无法支持映像生成方案,则可以请求增加 Azure 容器实例配额。
独立映像生成功能导致失败
错误
由于独立映像生成的问题,VM 映像生成器生成失败。
原因
由于本文其他位置列出的原因,VM 映像生成器生成可能会失败。 但是,根据你的场景、订阅配额或某些不可预见的服务错误,独立映像生成问题导致生成失败的可能性很小。 有关详细信息,请参阅独立映像生成。
解决方案
如果你确定生成因独立映像生成问题而失败,请确保:
- 没有 Azure 策略 阻止部署本文的 “先决条件 ”部分中提到的资源(特别是 Azure 容器实例)。
- 订阅有足够的 Azure 容器实例配额来支持所有并发映像生成。 有关详细信息,请参阅本文 的“订阅已超出 Azure 容器实例配额 ”部分。
VM 映像生成器当前正在部署独立映像生成。 特定映像模板不绑定到独立映像生成,同一映像模板在不同生成期间可能或可能不会使用独立映像生成。
若要临时运行生成,而无需独立映像生成,请重试生成。 由于映像模板未绑定到独立映像生成功能,因此在重试构建时,很可能是在不使用独立映像生成的情况下重新运行。
如果这些解决方案都无法缓解映像生成失败的情况,可以联系 Azure 支持人员暂时选择订阅退出独立映像生成。 有关详细信息,请参阅创建 Azure 支持请求。
注意
如果隔离映像生成功能最终在所有区域和模板中启用,则上述缓解措施将只是临时的。 最好找出生成失败的根本原因。
上下文取消后,生成被取消
错误
PACKER ERR 2020/03/26 22:11:23 Cancelling builder after context cancellation context canceled
PACKER OUT Cancelling build after receiving terminated
PACKER ERR 2020/03/26 22:11:23 packer-builder-azure-arm plugin: Cancelling hook after context cancellation context canceled
..
PACKER ERR 2020/03/26 22:11:23 packer-builder-azure-arm plugin: Cancelling provisioning due to context cancellation: context canceled
PACKER ERR 2020/03/26 22:11:25 packer-builder-azure-arm plugin: [ERROR] Remote command exited without exit status or exit signal.
PACKER ERR 2020/03/26 22:11:25 packer-builder-azure-arm plugin: [INFO] RPC endpoint: Communicator ended with: 2300218
PACKER ERR 2020/03/26 22:11:25 [INFO] 148974 bytes written for 'stdout'
PACKER ERR 2020/03/26 22:11:25 [INFO] 0 bytes written for 'stderr'
PACKER ERR 2020/03/26 22:11:25 [INFO] RPC client: Communicator ended with: 2300218
PACKER ERR 2020/03/26 22:11:25 [INFO] RPC endpoint: Communicator ended with: 2300218
原因
VM 映像生成器使用端口 22 (Linux) 或 5986 (Windows) 连接到生成 VM。 如果在映像生成期间服务与生成 VM 断开连接,则会出现此问题。 断开连接的原因可能会有所不同,但在脚本中启用或配置防火墙可能会阻止前面提到的端口。
解决方案
复查脚本,查看防火墙更改或启用情况,或者 SSH 或 WinRM 更改。 确保任何更改都允许在服务与前面提到的端口上的生成 VM 之间建立持续连接。 有关详细信息,请参阅 VM 映像生成器网络选项。
JWT 错误出现于构建初期日志中
错误
在构建过程的早期阶段,构建失败,并且日志显示 JSON Web 令牌 (JWT) 错误:
PACKER OUT Error: Failed to prepare build: "azure-arm"
PACKER ERR
PACKER OUT
PACKER ERR * client_jwt will expire within 5 minutes, please use a JWT that is valid for at least 5 minutes
PACKER OUT 1 error(s) occurred:
原因
模板中的 buildTimeoutInMinutes
值设置为介于 1 到 5 分钟之间。
解决方案
如 “创建 VM 映像生成器”模板中所述,超时必须设置为 0 分钟才能使用默认值或设置为 5 分钟以上才能替代默认值。 将模板中的超时时间更改为 0 分钟以使用默认值,或将其更改为至少 6 分钟。
出现资源删除错误
错误
中间资源在生成结束时将被清理,自定义日志可能会显示几条资源删除错误:
PACKER OUT ==> azure-arm: Error deleting resource. Will retry.
...
PACKER OUT ==> azure-arm: Error: network.PublicIPAddressesClient#Delete: Failure sending request: StatusCode=0 -- Original Error: Code="PublicIPAddressCannotBeDeleted" Message=...
...
PACKER ERR 2022/03/07 18:43:06 packer-plugin-azure plugin: 2022/03/07 18:43:06 Retryable error: network.SecurityGroupsClient#Delete: Failure sending request: StatusCode=0 -- Original Error: Code="InUseNetworkSecurityGroupCannotBeDeleted"...
原因
这些错误日志消息基本无害,因为资源删除会被多次重试。 通常,他们最终成功了。 可以继续遵循删除日志来验证此行为,直到观察到成功消息。 或者,可以检查过渡资源组,以确认是否已删除该资源。
在生成失败时进行这些观察尤为重要。 这些错误消息可能会导致你得出结论,即使实际错误可能在其他位置,这些错误也是失败的原因。
错误
当映像停滞在模板删除中时,自定义日志可能会显示以下错误:
error deleting resource id /subscriptions/<subscriptionID>/resourceGroups/<rgName>/providers/Microsoft.Network/networkInterfaces/<networkInterfacName>: resources.Client#DeleteByID: Failure sending request: StatusCode=400 --
Original Error: Code="NicInUseWithPrivateEndpoint"
Message="Network interface /subscriptions/<subscriptionID>/resourceGroups/<rgName>/providers/Microsoft.Network/networkInterfaces/<networkInterfacName> cannot be deleted because it is currently in use with an private endpoint (/subscriptions/<subscriptionID>/resourceGroups/<rgName>/providers/Microsoft.Network/privateEndpoints/<pIname>)." Details=[]
原因
发生该错误的原因是网络接口当前正在与专用终结点一起使用。
解决方案
若要解决此问题,请按此特定顺序逐个删除以下资源:
- 专用终结点连接。 可以通过在“专用链接服务”资源页面的 “专用终结点连接” 选项卡中找到此连接。
- 专用链接服务。
- 网络接口和负载均衡器。
- 资源组。
- 图片模板。
如需更多帮助,可以 联系 Azure 支持 人员来解决停滞删除错误。
在更新请求中找不到分发目标
错误
Validation failed: Distribute target with Runoutput name <runoutputname> not found in the update request. Deleting a distribution target is not allowed.
原因
如果在修补请求正文中找不到现有分发目标,则会发生此错误。
解决方案
分布数组应包含所有分布目标:新目标(如果有)、没有更改的现有目标以及更新的目标。 如果要删除现有分发目标,请删除并重新创建映像模板。 目前不支持通过修补程序 API 删除分发目标。
缺少必填字段
错误
Validation failed: 'ImageTemplate.properties.distribute[<index>]': Missing field <fieldname>. Please review http://aka.ms/azvmimagebuildertmplref for details on fields required in the Image Builder Template.
原因
当分发目标缺少所需字段时,将发生此错误。
解决方案
创建请求时,请确保提供分发目标中的每个必需字段,即使没有更改也是如此。
排查 Azure DevOps 问题
仅当自定义过程中发生错误时,Azure DevOps 任务才会失败。 发生此错误时,任务会报告失败并离开临时资源组,并记录日志,以便可以识别问题。
若要查找日志,请执行以下步骤:
查找模板名称。 转到“管道”>“失败的生成”,然后向下钻取到 VM 映像生成器中的 Azure DevOps 任务。 记下
template name
该值。start reading task parameters... found build at: /home/vsts/work/r1/a/_ImageBuilding/webapp end reading parameters getting storage account details for aibstordot1556933914 created archive /home/vsts/work/_temp/temp_web_package_21475337782320203.zip Source for image: { type: 'SharedImageVersion', imageVersionId: '/subscriptions/<subscriptionID>/resourceGroups/<rgName>/providers/Microsoft.Compute/galleries/<galleryName>/images/<imageDefName>/versions/<imgVersionNumber>' } template name: t_1556938436xxx
转到 Azure 门户,在资源组中搜索模板名称,然后输入 IT_搜索资源组。
选择存储帐户名称,然后选择 Blob>容器>日志。
可能偶尔需要调查成功的生成并查看其日志。 如前所述,如果映像生成成功,则会删除包含日志的暂存资源组作为清理的一部分。 为防止自动清除,可以在内联命令后引入 sleep
,然后在暂停构建时查看日志。
- 通过添加
Write-Host / Echo "Sleep"
来更新内联命令。 这个增补让您有更多时间在日志中搜索。 - 使用
Start-Sleep
或Sleep
Linux 命令添加至少 10 分钟的sleep
值。 - 使用此方法确定日志位置,然后继续下载或检查日志,直至其到达
sleep
。
操作已取消
错误
2020-05-05T18:28:24.9280196Z ##[section]Starting: Azure VM Image Builder Task
2020-05-05T18:28:24.9609966Z ==============================================================================
2020-05-05T18:28:24.9610739Z Task : Azure VM Image Builder Test
2020-05-05T18:28:24.9611277Z Description : Build images using Azure Image Builder resource provider.
2020-05-05T18:28:24.9611608Z Version : 1.0.18
2020-05-05T18:28:24.9612003Z Author : Microsoft Corporation
2020-05-05T18:28:24.9612718Z Help : For documentation, and end to end example, please visit: http://aka.ms/azvmimagebuilderdevops
2020-05-05T18:28:24.9613390Z ==============================================================================
2020-05-05T18:28:26.0651512Z start reading task parameters...
2020-05-05T18:28:26.0673377Z found build at: d:\a\r1\a\_AppsAndImageBuilder\webApp
2020-05-05T18:28:26.0708785Z end reading parameters
2020-05-05T18:28:26.0745447Z getting storage account details for aibstagstor1565047758
2020-05-05T18:28:29.8812270Z created archive d:\a\_temp\temp_web_package_09737279437949953.zip
2020-05-05T18:28:33.1568013Z Source for image: { type: 'PlatformImage',
2020-05-05T18:28:33.1584131Z publisher: 'MicrosoftWindowsServer',
2020-05-05T18:28:33.1585965Z offer: 'WindowsServer',
2020-05-05T18:28:33.1592768Z sku: '2016-Datacenter',
2020-05-05T18:28:33.1594191Z version: '14393.3630.2004101604' }
2020-05-05T18:28:33.1595387Z template name: t_1588703313152
2020-05-05T18:28:33.1597453Z starting put template...
2020-05-05T18:28:52.9278603Z put template: Succeeded
2020-05-05T18:28:52.9281282Z starting run template...
2020-05-05T19:33:14.3923479Z ##[error]The operation was canceled.
2020-05-05T19:33:14.3939721Z ##[section]Finishing: Azure VM Image Builder Task
原因
如果用户未取消构建,Azure DevOps 用户代理就会取消它。 很可能,由于 Azure DevOps 功能,发生了一小时的超时。 如果你使用专用项目和代理,会获得 60 分钟的生成时间。 如果生成超过超时值,Azure DevOps 将取消正在运行的任务。
有关 Azure DevOps 功能和限制的详细信息,请参阅 Microsoft 托管的代理。
解决方案
可以托管自己的 Azure DevOps 代理,或尝试减少生成时间。 例如,如果要分发到 Azure Compute Gallery,则可以将它们复制到一个区域或异步复制它们。
Windows 登录速度缓慢
错误
使用 VM 映像生成器创建 Windows 10映像,从该映像创建 VM,然后使用远程桌面协议 (RDP) 时,可能会出现此错误。 在首次登录屏幕上等待几分钟,然后蓝色屏幕会显示以下消息:
Please wait for the Windows Modules Installer
解决方案
在映像生成中,确保:
- 添加 Windows 重启定制器作为最后一个自定义后,不会有任何待完成的重启。
- 所有软件安装都已完成。
将
/mode:vm
选项添加到 VM 映像生成器使用的默认Sysprep
命令。 有关详细信息,请参阅本文后面的 替代命令 。
排查从 VM 映像生成器创建 VM 失败的问题
默认情况下,VM 映像生成器在每个映像自定义阶段结束时运行取消预配代码,以 通用化 映像。 通用化映像会将其设置为在创建多个 VM 时重复使用。 在此过程中,可以传入 VM 设置,例如主机名和用户名。
在 Windows 中,VM 映像生成器运行泛型 Sysprep
命令。 但是,此命令可能并不适合每个成功的 Windows 通用化。 借助 VM 映像生成器,可以自定义 Sysprep
命令。 VM 映像生成器是一种映像自动化工具,负责成功运行 Sysprep
命令。 但是,你可能需要不同的 Sysprep
命令来使映像可重复使用。
在 Linux 中,VM 映像生成器运行泛型 waagent -deprovision+user
命令。 有关详细信息,请参阅 Microsoft Azure Linux 代理文档。
如果要迁移现有自定义项并使用各种 Sysprep
或 waagent
命令,则可以尝试 VM 映像生成器通用命令。 如果 VM 创建失败,请使用你以前的 Sysprep
或 waagent
命令。
假设你已成功使用 VM 映像生成器创建 Windows 自定义映像,但未能从映像成功创建 VM。 例如,VM 创建无法完成或超时。在这种情况下,请执行以下任务之一:
- 查看 Windows Server
Sysprep
文档。 - 向 Windows Server
Sysprep
客户支持团队提出支持请求。 该团队可以帮助解决问题,并提供有关正确Sysprep
命令的建议。
命令位置和文件名
在 Windows 中:
c:\DeprovisioningScript.ps1
在 Linux 中:
/tmp/DeprovisioningScript.sh
适用于 Windows 的 Sysprep 命令
Write-Output '>>> Waiting for GA Service (RdAgent) to start ...'
while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }
Write-Output '>>> Waiting for GA Service (WindowsAzureTelemetryService) to start ...'
while ((Get-Service WindowsAzureTelemetryService) -and ((Get-Service WindowsAzureTelemetryService).Status -ne 'Running')) { Start-Sleep -s 5 }
Write-Output '>>> Waiting for GA Service (WindowsAzureGuestAgent) to start ...'
while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }
Write-Output '>>> Sysprepping VM ...'
if( Test-Path $Env:SystemRoot\system32\Sysprep\unattend.xml ) {
Remove-Item $Env:SystemRoot\system32\Sysprep\unattend.xml -Force
}
& $Env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /quiet /quit
while($true) {
$imageState = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State).ImageState
Write-Output $imageState
if ($imageState -eq 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { break }
Start-Sleep -s 5
}
Write-Output '>>> Sysprep complete ...'
适用于 Linux 的取消预配命令
sudo /usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync
重写命令
若要重写命令,请使用 PowerShell 或 shell 脚本预配程序创建具有确切文件名的命令文件。 将它们放在前面列出的目录中。 VM 映像生成器读取这些命令并将输出 customization.log
写入文件。
获取支持
如果使用了本文中的指南,但仍遇到问题,可以提出支持案例。
使用以下代码选择正确的产品和支持主题。 这样做可确保已连接到 Azure VM 映像生成器支持团队。
Product Family: Azure
Product: Virtual Machine Running (Window\Linux)
Support Topic: Azure Features
Support Subtopic: Azure Image Builder