你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

对 Azure VM 映像生成器进行故障排除

适用于:✔️ Linux VM ✔️ 灵活规模集

使用本文可排查和解决使用 Azure VM 映像生成器时可能会遇到的常见问题。

先决条件

创建生成时,会执行以下操作:

  • VM 映像生成器服务使用 WinRM 或 Secure Shell (SSH) 与生成 VM 通信。 请勿*在生成过程中禁用这些设置。
  • VM 映像生成器在生成过程中会在过渡资源组中创建资源。 请务必验证 Azure Policy 不会阻止 VM 映像生成器创建或使用所需资源。
  • 验证 Azure Policy 未在生成 VM 上安装意外功能(例如 Azure 扩展)。
  • 确保 VM 映像生成器具有读取/写入映像和连接到存储帐户的正确权限。 有关详细信息,请查看适用于 Azure CLIAzure PowerShell 的权限文档。
  • 如果脚本或内联命令失败并显示错误(非零退出代码),则 VM 映像生成器会使生成失败。 确保测试了自定义脚本,并验证了它们是否可在没有错误的情况下运行(退出代码 0)或需要用户输入。 有关详细信息,请参阅使用 VM 映像生成器和 PowerShell 创建 Azure 虚拟桌面映像
  • 请确保订阅有足够的 Azure 容器实例配额
    • 每个映像生成最多可以部署临时资源组中的一个临时 Azure 容器实例资源(四个标准核心)。 独立映像生成需要这些资源。

VM 映像生成器失败可能发生在两个方面:

  • 映像模板提交期间
  • 映像生成期间

注意

由 CIS 管理的 Azure 市场上的 CIS 强化映像(Linux 或 Windows)可能会因其配置而导致 Azure 映像生成器服务生成失败。 例如:

  • CIS 强化的 Windows 映像可能会中断 WinRM 连接,这是 AIB 生成的先决条件。
  • CIS Linux 映像可能因 chmod +x 权限问题而失败。

排查映像模板提交错误

映像模板提交错误只在提交时返回。 映像模板提交错误没有错误日志。 如果在提交期间出现了错误,可通过检查模板的状态(具体来说是查看 ProvisioningStateProvisioningErrorMessage/provisioningError)来返回该错误。

az image builder show --name $imageTemplateName  --resource-group $imageResourceGroup
Get-AzImageBuilderTemplate -ImageTemplateName  <imageTemplateName> -ResourceGroupName <imageTemplateResourceGroup> | Select-Object ProvisioningState, ProvisioningErrorMessage

注意

对于 PowerShell,需要安装 VM 映像生成器 PowerShell 模块

重要

API 版本 2021-10-01 引入了对错误架构的更改,该架构将成为每个未来 API 版本的一部分。 如果有任何 Azure VM 映像生成器自动化,请注意切换到 API 版本 2021-10-01 或更高版本时的新错误输出。 建议在切换到最新 API 版本后,不要还原到较早版本,因为必须再次更改自动化才能生成较早的错误架构。 我们预计不会在将来版本中再次更改错误架构。

版本 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."
  }
}

以下部分提供常见映像模板提交错误的问题解决指南。

目前不支持更新或升级映像模板

错误

'Conflict'. Details: Update/Upgrade of image templates is currently not supported

原因

模板已存在。

解决方案

如果提交映像配置模板,并且提交失败,那么,失败的模板项目仍然会存在。 请删除该失败的模板。

在映像模板上重新分配 MSI

错误

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.

原因

在某些情况下,无法使用分配给映像模板的托管服务标识 (MSI)

  • 映像生成器模板使用客户提供的暂存资源组,在删除映像模板之前会删除 MSI(暂存资源组方案)
  • 不能使用创建用于分配给映像模板的托管服务标识 (MSI)

解决方案

使用 Azure CLI 重置映像模板上的标识。 确保将 Azure CLI 更新到 2.45.0 或更高版本。

从目标映像生成器模板中删除托管标识

az image builder identity remove -g <template resource group> -n <template name> --user-assigned <identity resource id>

将标识重新分配给目标映像生成器模板

az image builder identity assign -g <template rg> -n <template name> --user-assigned <identity resource id>

资源操作已完成,终端预配状态为“失败”

错误

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'..

原因

文件名或位置不正确,或无法访问该位置。

解决方案

确保可以访问该文件。 验证名称和位置是否正确。

创建磁盘时出现授权错误

Azure 映像生成器生成失败,出现如下所示的授权错误:

错误

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 源映像为 Azure 映像生成器服务指定预先存在的资源组和 VNet 时,会导致此错误。

解决方案

需要使用下面的 CLI 命令或门户说明,将参与者角色分配给与 Azure 映像生成器的第一方应用对应的服务主体的资源组。

首先,使用以下 CLI 命令验证服务主体是否与 Azure 映像生成器的第一方应用关联:

az ad sp show --id {servicePrincipalName, or objectId}

然后,若要使用 CLI 实现此解决方案,请使用以下命令:

az role assignment create -g {ResourceGroupName} --assignee {AibrpSpOid} --role Contributor

若要在门户中实现此解决方案,请按照本文档中的说明操作:使用 Azure 门户分配 Azure 角色 - Azure RBAC

对于步骤 1:确定所需的范围:所需的范围是资源组。

对于步骤 3:选择适当的角色:角色为参与者。

对于步骤 4:选择需要访问权限的人员:选择成员“Azure 虚拟机映像生成器”

然后继续执行步骤 6:分配角色以分配角色。

排查生成故障

对于映像生成失败,可从 lastrunstatus 获取错误,然后在 customization.log 文件中查看详细信息。

az image builder show --name $imageTemplateName  --resource-group $imageResourceGroup
Get-AzImageBuilderTemplate -ImageTemplateName  <imageTemplateName> -ResourceGroupName <imageTemplateResourceGroup> | Select-Object LastRunStatus, LastRunStatusMessage

自定义日志

在映像生成运行时,会创建日志并将其存储在存储帐户中。 在你创建映像模板项目时,VM 映像生成器会在临时资源组中创建存储帐户。

存储帐户名称使用以下模式:IT_<ImageResourceGroupName><TemplateName><GUID>(例如 IT_aibmdi_helloImageTemplateLinux01)。

若要查看资源组中的 customization.log 文件,请选择“存储帐户”>“Blob”>“packerlogs”,选择“目录”,然后选择 customization.log 文件。

了解自定义日志

该日志为详细的日志。 其中涉及映像生成,包括映像分发方面的任何问题,如 Azure Compute Gallery 复制。 这些错误会出现在映像模板状态的错误消息中。

customization.log 文件包括以下阶段:

  1. 使用 ARM 模板将生成 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 ...
    ..
    
  2. 部署阶段的状态。 此阶段包括每个资源部署的状态:

    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=""
    
  3. 连接到生成 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!
    
  4. 运行自定义阶段。 在自定义运行时,可以通过查看 customization.log 文件来识别它们。 搜索“(遥测)”。

    (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 hasfinished
    
  5. 取消预配阶段。 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."}
    
  6. 清理阶段。 生成完成后,将删除 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 和防火墙允许连接到远程资源。
  • 使用 Write-Hostecho 将注释输出到控制台。 这样做可以搜索 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 密钥保管库。 目前,Azure 映像生成器不支持此配置。

解决方案

必须在启用公共访问的情况下创建 Azure 密钥保管库。

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."

原因

自定义失败。

解决方案

查看日志以查找定制器失败。 搜索“(遥测)”。

例如:

(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”中。

解决方案

  1. 查看 customization.log 文件。 标识要运行的最后一个定制器。 从日志底部开始搜索 (telemetry)。

  2. 检查脚本自定义。 自定义可能不会取消命令的用户交互,如 quiet 选项。 例如,apt-get install -y 会导致脚本执行等待用户交互。

  3. 如果使用 File 定制器来下载大于 20 MB 的项目,请参阅解决方法部分。

  4. 查看脚本中可能会导致脚本等待的错误和依赖项。

  5. 如果预计自定义需要更多时间,请增加 buildTimeoutInMinutes 的值。 默认值为 4 小时。

  6. 如果有大量占用资源的操作(例如下载千兆字节 (GB) 的文件),请考虑基础的生成 VM 大小。 该服务会使用 Standard_D1_v2 VM。 该 VM 具有 1 个 vCPU 和 3.5 GB 内存。 如果要下载 50 GB,可能会耗尽 VM 资源,并导致 VM 映像生成器与生成 VM 之间发生通信故障。 请通过设置 VM_size来使用更大内存的 VM 重试生成。

文件下载时间过长

错误

[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 中可以使用 wgetcurl。 在 Windows 中可以使用 Invoke-WebRequest

生成器无法运行 Windows-Restart 的情况持续存在,显示错误代码 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 更新步骤在基于 Windows Server 2016 的映像中过早声明。

解决方案

restartTimeout 从 15 分钟增加到 30 分钟。

错误

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 Compute Gallery 完成复制。 即使该生成已经失败,复制也仍会继续。 可以通过检查分发 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 或 PowerShell 命令:

  • Azure CLI: az provider register -n Microsoft.ContainerInstance
  • PowerShell:Register-AzResourceProvider -ProviderNamespace Microsoft.ContainerInstance

超出 Azure 容器实例配额

错误

Azure Container Instances quota exceeded"

原因

订阅没有足够的 Azure 容器实例 (ACI) 配额,Azure 映像生成器无法成功生成映像。

解决方案

可以执行以下操作,使 ACI 配额可用于 Azure 映像生成器:

  • 查找订阅中 Azure 容器实例的其他使用情况,并删除任何不需要的实例,使配额可用于 Azure 映像生成器。
  • Azure 映像生成器仅在生成发生时暂时部署 ACI。 生成完成后,将删除这些实例。 如果订阅中发生过多的并发映像生成,则可以考虑延迟某些映像生成。 这会减少订阅中 ACI 的并发使用情况。 如果映像模板是使用触发器为自动映像生成设置的,则 Azure 映像生成器会自动重试此类失败的生成。
  • 如果订阅的当前 ACI 限制太低,无法支持映像生成方案,则可以请求增加你的 ACI 配额

注意

独立映像生成需要 ACI 资源。

在一段时间内部署的 Azure 容器实例过多

错误

“在一段时间内部署的 Azure 容器实例过多”

原因

订阅没有足够的 Azure 容器实例 (ACI) 配额,Azure 映像生成器无法同时成功生成映像。

解决方案

您可以执行下列操作:

  • 以更少的并发方式重试失败的生成。
  • 如果订阅的当前 ACI 限制太低,无法支持映像生成方案,则可以请求增加你的 ACI 配额

独立映像生成失败

错误

由于独立映像生成,Azure 映像生成器生成失败。

原因

Azure 映像生成器生成可能会因本文档其他位置列出的原因而失败。 但是,由于独立映像生成造成生成失败的可能性很小,具体取决于你的方案、订阅配额或某些无法预见的服务错误。 有关详细信息,请参阅独立映像生成

解决方案

如果确定生成由于独立映像生成而失败,则可以执行以下操作:

  • 确保没有 Azure Policy 阻止部署先决条件部分中提到的资源,特别是 Azure 容器实例、Azure 虚拟网络和 Azure 专用终结点。
  • 请确保订阅有足够的 Azure 容器实例配额来支持所有并发映像生成。 有关详细信息,请参阅 Azure 容器实例超出配额

Azure 映像生成器目前正在部署独立映像生成。 特定映像模板不会绑定到独立映像生成,并且同一映像模板在不同生成期间可能会或可能不会利用独立映像生成。 可以执行以下操作来临时运行生成,而无需独立映像生成。

  • 重试生成。 由于映像模板未绑定到独立映像生成功能,重试生成时,在不使用独立映像生成的情况下,重新运行的可能性很高。

如果这些解决方案都无法缓解映像生成失败的情况,则可以联系 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=[]

原因

发生此错误的原因是网络接口当前正与专用终结点一起使用。

解决方案

若要解决此问题,请按特定顺序逐个删除以下资源:

  1. 专用终结点连接。 通过转到专用链接服务资源页上的“专用终结点连接”选项卡,在专用链接服务资源中找到此链接。
  2. 专用链接服务。
  3. 网络接口和负载均衡器。
  4. 资源组。
  5. 映像模板。

如需其他帮助,可以联系 Azure 支持以解决删除操作停滞的错误。

在更新请求中找不到分发目标

错误

Validation failed: Distribute target with Runoutput name <runoutputname> not found in the update request. Deleting a distribution target is not allowed.

原因

如果在 Patch 请求正文中找不到现有分发目标,则会发生此错误。

解决方案

分布数组应包含所有分布目标,即新目标(如果有)、没有更改的现有目标和更新的目标。 如果要删除现有分发目标,请删除并重新创建映像模板,因为当前不支持通过 Patch 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.

原因

当分发目标中缺少必填字段时,会发生此错误。

解决方案

创建请求时,请提供分发目标中的每个必需字段,即使没有更改也是如此。

DevOps 任务

对任务进行故障排除

仅当在自定义过程中发生错误时,任务才会失败。 发生这种情况时,任务会报告失败,并将暂存资源组保留在日志中,以便你可以确定问题所在。

若要查找日志,需要知道模板名称。 转到“管道”>“失败的生成”,然后向下钻取到 VM 映像生成器 DevOps 任务。

你会看到日志和模板名称:

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
  1. 转到 Azure 门户,在资源组中搜索模板名称,然后通过键入 IT_* 来搜索资源组。
  2. 选择存储帐户名称 >“blob”>“容器”>“日志”。

对成功的生成进行故障排除

有时可能需要调查成功的生成并查看其日志。 如前所述,如果映像生成成功,在清理过程中将会删除包含日志的暂存资源组。 但是,若要防止自动清理,可以在内联命令后面引入 sleep,然后在生成暂停时查看日志。 为此,请执行以下操作:

  1. 通过添加 Write-Host / Echo “Sleep” 来更新内联命令。 这使你有时间在日志中搜索。
  2. 使用 Start-SleepSleep Linux 命令添加至少 10 分钟的 sleep 值。
  3. 使用此方法确定日志位置,然后继续下载或检查日志,直至其到达 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 的功能,1 小时超时已经发生了。 如果你使用专用项目和代理,会获得 60 分钟的生成时间。 如果生成超过超时时间,DevOps 会取消正在运行的任务。

有关 Azure DevOps 功能和限制的详细信息,请参阅 Microsoft 托管的代理

解决方案

你可以托管自己的 DevOps 代理,也可以考虑减少生成的时间。 例如,如果要分发到 Azure Compute Gallery,则可以将它们复制到一个区域或异步复制它们。

Windows 登录速度缓慢

错误

使用 VM 映像生成器创建 Windows 10映像,从该映像创建 VM,然后使用远程桌面协议 (RDP) 时,可能会出现此错误。 在首次登录屏幕上等待几分钟,然后蓝色屏幕会显示以下消息:

Please wait for the Windows Modules Installer

解决方案

  1. 在映像生成中,检查以确保:

    • 通过添加 Windows 重启定制器作为最后一个自定义来检查是否没有任何未完成的重启。
    • 所有软件安装都已完成。
  2. /mode:vm 选项添加到 VM 映像生成器使用的默认 Sysprep。 有关详细信息,请转到“从 VM 映像生成器映像创建的 VM 未成功创建”下的“替代命令”部分。

从 VM 映像生成器映像创建的 VM 未成功创建

在默认情况下,VM 映像生成器会在每个映像自定义阶段结束时运行 deprovision 代码,以通用化该映像。 通用化映像是将它设置为可重复用于创建多个 VM。 在该过程中,可以传入 VM 设置,例如主机名、用户名等。 在 Windows 中,VM 映像生成器会运行 Sysprep,在 Linux 中,VM 映像生成器会运行 waagent -deprovision

在 Windows 中,VM 映像生成器使用通用的 Sysprep 命令。 但是,此命令可能并不适合每个成功的 Windows 通用化。 借助 VM 映像生成器,可以自定义 Sysprep 命令。 请注意,VM 映像生成器是负责成功运行 Sysprep 命令的映像自动化工具。 但是,你可能需要不同的 Sysprep 命令来使映像可重复使用。 在 Linux 中,VM 映像生成器使用通用的 waagent -deprovision+user 命令。 有关详细信息,请参阅 Microsoft Azure Linux 代理文档

如果要迁移现有自定义项并使用各种 Sysprepwaagent 命令,则可以尝试 VM 映像生成器通用命令。 如果 VM 创建失败,请使用你以前的 Sysprepwaagent 命令。

假设你已成功使用 VM 映像生成器创建了 Windows 自定义映像,但未能从该映像成功创建 VM。 例如,VM 创建未能完成或超时。在此事件中,执行以下任一操作:

  • 查看 Windows Server Sysprep 文档。
  • 向 Windows Server Sysprep 客户服务支持团队提出支持请求。 他们可以帮助你解决问题,并提供有关正确 Sysprep 命令的建议。

命令位置和文件名

在 Windows 中:

c:\DeprovisioningScript.ps1

在 Linux 中:

/tmp/DeprovisioningScript.sh

Sysprep 命令:Windows

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 ...'

-deprovision 命令: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

后续步骤

有关详细信息,请参阅 VM 映像生成器概述