針對 Azure VM Image Builder 進行疑難排解

適用於:✔️ Linux VM ✔️ 彈性擴展集

使用本文來針對您使用 Azure VM Image Builder 時可能會遇到的常見問題進行疑難排解並加以解決。

必要條件

當您建立組建時,請進行下列步驟:

  • VM Image Builder 服務會使用 WinRM 或安全殼層 (SSH) 與組建 VM 通訊。 請勿*在組建中停用這些設定。
  • VM Image Builder 會在暫存資源群組中建立資源,作為組建的一部分。 請務必確認 Azure 原則不會防止 VM Image Builder 建立或使用必要的資源。
  • 確認 Azure 原則不會在組建 VM 上安裝非預期的功能,例如 Azure 擴充功能。
  • 確定 VM Image Builder 具有正確權限,可讀取/寫入映像和連線到儲存體帳戶。 如需詳細資訊,請檢閱 Azure CLIAzure PowerShell 的權限說明文件。
  • 如果命令碼或內嵌命令失敗,VM Image Builder 會失敗並包含錯誤 (非零結束代碼)。 請確定您已測試自訂指令碼,並確認執行時沒有錯誤 (結束代碼 0) 或需要使用者輸入。 如需更多資訊,請參閱使用 VM Image Builder 和 PowerShell,建立 Azure 虛擬桌面映像
  • 請確定您的訂用帳戶有足夠的 Azure 容器執行個體配額
    • 每個映像建置最多可以部署暫存資源群組中的一個暫存 Azure 容器執行個體資源 (四個標準核心)。 隔離式映像建置需要這些資源。

VM Image Builder 失敗可能發生在兩個區域中:

  • 在映像範本提交期間
  • 在映像組建期間

注意

由 CIS 所管理 Azure Marketplace 上的 CIS 強化映像 (Linux 或 Windows) 可能會因為其設定而造成 Azure Image Builder 服務的建置失敗。 例如:

  • 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 Image Builder PowerShell 模組

重要

API 版本 2021-10-01 引進了錯誤結構描述的變更,該結構描述將會成為未來每個 API 發行版本的一部分。 如果您有任何 Azure VM Image Builder 自動化,在切換到 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)

解決方案

使用 Azure CLI 重設映像範本上的身分識別。 請確定您將 Azure CLI 更新為 2.45.0 版或更新版本。

從目標 Image Builder 範本中移除受控識別

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

將身分識別重新指派給目標 Image Builder 範本

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 Image Builder 可能需要下列權限:

  • 來源映像或 Azure Compute Gallery (先前稱為共用映像庫) 資源群組。
  • 散發映像或 Azure Compute Gallery 資源。
  • File 自訂工具正在存取的儲存體帳戶、容器或 Blob。

此外,請確定為每個映像範本指定的暫存資源群組名稱並未重複。

如需關於設定權限的更多資訊,請參閱使用 Azure CLI 設定 VM Image Builder 權限使用 PowerShell 設定 VM Image Builder 權限

取得受控映像時發生錯誤

錯誤

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 Image Builder 可能需要下列權限:

  • 來源映像或 Azure Compute Gallery 資源群組。
  • 散發映像或 Azure Compute Gallery 資源。
  • File 自訂工具正在存取的儲存體帳戶、容器或 Blob。

如需關於設定權限的更多資訊,請參閱使用 Azure CLI 設定 VM Image Builder 權限使用 PowerShell 設定 VM Image Builder 權限

映像版本的建置步驟失敗

錯誤

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 Image Builder 找不到來源映像。

解決方案

請確定來源映像正確,且存在於 VM Image Builder 的位置。

將外部檔案下載至本機檔案

錯誤

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 Image Builder 組建失敗,且授權錯誤如下所示:

錯誤

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

原因

嘗試將預先存在的資源群組和 VNet 指定給具有 Windows 來源映像的 Azure Image Builder 服務時,就會發生此錯誤。

解決方案

您必須使用下列 CLI 命令或入口網站指示,將參與者角色指派給對應至 Azure Image Builder 第一方應用程式之服務主體的資源群組。

首先,使用下列 CLI 命令,驗證服務主體是否與 Azure Image Builder 的第一方應用程式相關聯:

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 虛擬機器 Image Builder」

然後繼續進行步驟 6:指派角色以指派角色。

針對組建失敗進行疑難排解

針對映像建置失敗,請從 lastrunstatus 取得錯誤,然後檢閱 customization.log 檔案中的詳細資料。

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

自訂記錄

當執行映像組建時,會建立記錄並將記錄儲存在儲存體帳戶中。 當您建立映像範本成品時,VM Image Builder 會在階段資源群組中建立儲存體帳戶。

儲存體帳戶會使用模式 IT_<ImageResourceGroupName><TemplateName><GUID> (例如:IT_aibmdi_helloImageTemplateLinux01)。

若要檢視資源群組中的 customization.log 檔案,請選取 [儲存體帳戶]>[Blob]>packerlogs、選取 [目錄],然後選取 customization.log 檔案。

了解自訂記錄

記錄檔是詳細資訊。 其涵蓋映像組建,包括映像散發的任何問題,例如 Azure Compute Gallery 複寫。 這些錯誤會顯示在映像範本狀態的錯誤訊息中。

customization.log 檔案包含下列階段:

  1. 「使用 ARM 範本將組建 VM 和相依性部署到 IT_ staging 資源群組」階段。 此階段包含多個 POST 至 VM Image Builder 資源提供者:

    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 Image Builder 會使用 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 Image Builder 會使用 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 Image Builder 會新增隱藏的自訂工具。 此取消佈建步驟用於準備 VM 以進行取消佈建。 在 Windows 中,將會使用 c:\DeprovisioningScript.ps1 執行 Sysprep。 在 Linux 中,將會使用 /tmp/DeprovisioningScript.sh 執行 waagent-deprovision

    例如:

    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 Image Builder 資源。

    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 Image Builder。
  • 確保 Azure 原則和防火牆允許連線到遠端資源。
  • 使用 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 Key Vault 的結果。 目前,Azure Image Builder 不支援此設定。

解決方案

必須建立已啟用公用存取權的 Azure Key Vault。

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 Image Builder 與組建 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 Update 步驟會根據 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 Image Builder 逾時,等待映像新增並複寫至 Azure Compute Gallery。 如果映像正在插入資源庫中,您可以假設映像組建成功。 不過,整體流程失敗,因為 VM Image Builder 正在等候 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

原因

資源耗盡。 使用預設組建 VM 大小 D1_V2 執行 Windows Update 時,很常發生此問題。

解決方案

增加組建 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 Image Builder 具有所需的一切權限。

如需關於設定權限的更多資訊,請參閱使用 Azure CLI 設定 VM Image Builder 權限使用 PowerShell 設定 VM Image Builder 權限

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 Image Builder 會執行 Sysprep 命令以取消佈建。 當 VM Image Builder 取消佈建時,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 Image Builder 成功建置映像。

解決方案

您可以執行下列動作,讓 ACI 配額可供 Azure Image Builder 使用:

  • 查閱訂用帳戶中 Azure 容器執行個體的其他使用量,並移除任何不需要的執行個體,以便為 Azure Image Builder 提供配額。
  • Azure Image Builder 只會在建置進行時暫時部署 ACI。 建置完成後便會刪除這些執行個體。 如果您的訂用帳戶中發生太多並行映像建置,您可以考慮延遲部分映像建置。 這可減少訂用帳戶中 ACI 的並行使用量。 如果您的映像範本是針對使用觸發程序的自動映像建置所設定,則 Azure Image Builder 會自動重試此類失敗的建置。
  • 如果您的訂用帳戶目前 ACI 限制太低,無法支援您的映像建置案例,您可以要求增加 ACI 配額

注意

隔離式映像建置需要ACI 資源。

在一段時間內部署太多 Azure 容器執行個體

錯誤

「在一段時間內部署太多 Azure 容器執行個體」

原因

您的訂用帳戶沒有足夠的 Azure 容器執行個體 (ACI) 配額,可讓 Azure Image Builder 同時成功建置映像。

解決方案

您可以執行下列動作:

  • 以較少的並行方式重試失敗的組建。
  • 如果您的訂用帳戶目前 ACI 限制太低,無法支援您的映像建置案例,您可以要求增加 ACI 配額

隔離式映像建置失敗

錯誤

Azure Image Builder 組建因為隔離式映像建置而失敗。

原因

Azure Image Builder 組建可能會因為本文件中其他地方所列的原因而失敗。 不過,根據您的案例、訂用帳戶配額或某些未預期的服務錯誤,組建偶爾會因為隔離式映像建置而失敗。 如需詳細資訊,請參閱隔離式映像建置

解決方案

如果您判斷組建因隔離式映像建置而失敗,您可以執行下列動作:

  • 請確定沒有任何 Azure 原則封鎖〈必要條件〉一節中所述的資源部署,特別是 Azure 容器執行個體、Azure 虛擬網路和 Azure 私人端點。
  • 請確定您的訂用帳戶有足夠的 Azure 容器執行個體配額,以支援所有並行映像建置。 如需詳細資訊,請參閱 Azure 容器執行個體超出配額

Azure Image Builder 目前正在部署隔離式映像建置。 特定映像範本不會繫結至隔離式映像建置,且相同的映像範本可能會在不同的建置期間使用隔離式映像建置,或可能不會使用隔離式映像建置。 您可以執行下列動作來暫時執行組建,而不需隔離式映像建置。

  • 重試您的組建。 由於映像範本未繫結至隔離式映像建置功能,因此重試建置有很高的機率不需要隔離式映像建置即可重新執行。

如果這些解決方案都沒有緩解失敗的映像建置,您可以連絡 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 Image Builder 會使用連接埠 22 (Linux) 或 5986 (Windows) 連線至組建 VM。 在映像組建期間,如果服務與組建 VM 中斷連線就會發生此情況。 中斷連線的原因可能各不相同,但啟用或設定指令碼中的防火牆可能會封鎖上述的連接埠。

解決方案

檢閱您的連接埠,以瞭解防火牆變更或啟用或 SSH 或 WinRM 的變更,並確保服務與建置 VM 之間的任何變更都允許上述連接埠上的持續連線。 如需詳細資訊,請參閱 VM Image Builder 網路功能選項

建置初期記錄中的 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 Image Builder 範本中所述,逾時必須設定為 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.

原因

在修補檔要求本文中找不到現有的散發目標時,就會發生此錯誤。

解決方案

散發陣列應該包含所有散發目標,也就是新的目標 (如果有的話),現有的目標沒有變更和更新的目標。 如果您想要移除現有的散發目標,請刪除並重新建立映像範本,因為目前不支援透過修補檔 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 Image Builder 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 使用者代理程式會取消該組建。 1 小時逾時很可能是由 Azure DevOps 功能所導致。 如果您使用私人專案和代理程式,您會獲得 60 分鐘的組建時間。 如果組建超過逾時,DevOps 會取消執行中的工作。

如需 Azure DevOps 功能和限制的詳細資訊,請參閱 Microsoft 裝載的代理程式

解決方案

您可以裝載自己的 DevOps 代理程式,或查看減少組建的時間。 例如,如果您要散發至 Azure Compute Gallery,您可以將這些代理程式複寫至一個區域,或以非同步方式進行複寫。

緩慢的 Windows 登入

錯誤

當您使用 VM Image Builder 建立 Windows 10 映像、從映像建立 VM,然後使用遠端桌面通訊協定 (RDP) 時,可能會發生此錯誤。 您在第一次登入畫面會等候幾分鐘,然後出現藍色畫面並顯示下列訊息:

Please wait for the Windows Modules Installer

解決方案

  1. 在映像組建中,檢查以確定:

    • 透過將 Windows 重新啟動自訂工具新增為最後一項自訂工具,避免存在未完成的重新啟動。
    • 所有軟體皆已安裝完成。
  2. /mode:vm 選項新增至 VM Image Builder 所使用的預設 Sysprep。 如需詳細資訊,請移至「從 VM Image Builder 建立的 VM 未成功建立。」底下的 [覆寫命令] 區段。

從 VM Image Builder 建立的 VM 未成功建立

根據預設,VM Image Builder 會在每個映像自訂階段結束時執行 de-provision 程式碼,以將映像一般化。 將映像一般化是將其設定為重複使用以建立多個 VM。 在流程中,您可以傳入 VM 設定,例如主機名稱、使用者名稱等等。 在 Windows 中,VM Image Builder 會執行 Sysprep,並在 Linux 中,VM Image Builder 會執行 waagent -deprovision

如果使用 Windows,VM Image Builder 會使用一般 Sysprep 命令。 不過,此命令可能不適合每個成功的 Windows 一般化。 使用 VM Image Builder,您可以自訂 Sysprep 命令。 請注意,VM Image Builder 是負責成功執行 Sysprep 命令的映像自動化工具。 但您可能需要使用不同的 Sysprep 命令,讓您的映像可重複使用。 如果使用 Linux,VM Image Builder 會使用一般 waagent -deprovision+user 命令。 如需詳細資訊,請參閱 Microsoft Azure Linux 代理程式文件

如果您要移轉現有的自訂項目,並且正在使用各種 Sysprepwaagent 命令,您可以嘗試 VM Image Builder 一般命令。 如果 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 Image Builder 會讀取這些命令,並將輸出寫入至 customization.log 檔案。

取得支援

如果您在參考指南後仍有疑問,可以開啟支援案例。 請務必選取正確的產品和支援主題。 這麼做可確保您與 Azure VM Image Builder 支援小組連線。

選取案例產品:

Product Family: Azure
Product: Virtual Machine Running (Window\Linux)
Support Topic: Azure Features
Support Subtopic: Azure Image Builder

下一步

如需詳細資訊,請參閱 VM Image Builder 概觀