You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Packer使用vsphere-iso时传递build.ID报错ERR_ID_NOT_IMPLEMENTED_BY_BUILDER

Packer vsphere-iso构建器使用build.ID触发ERR_ID_NOT_IMPLEMENTED_BY_BUILDER错误

问题场景

使用Packer的vsphere-iso构建器时,尝试将build.ID传递给shell-local后处理器,控制台返回ERR_ID_NOT_IMPLEMENTED_BY_BUILDER错误。根据官方文档说明,build.ID在VMware环境中应对应VM名称,但实际调用时无法正常获取,核心需求是将生成的VM/模板名称传递给PowerShell后处理脚本。

官方文档描述

Here is the list of available build variables:

ID: Represents the VM being provisioned. For example, in Amazon it is the instance ID; in DigitalOcean, it is the Droplet ID; in VMware, it is the VM name.

后处理器配置(HCL)

post-processor "shell-local" {
  environment_vars = [
    "VCENTER_USER=${var.vsphere_username}",
    "VCENTER_PASSWORD=${var.vsphere_password}",
    "VCENTER_SERVER=${var.vsphere_endpoint}",
    "TEMPLATE_NAME=${build.ID}",
    "TEMPLATE_UUID=${local.build_uuid}",
  ]
  env_var_format  = "$env:%s=\"%s\"; "
  execute_command = ["${var.common_post_processor_cli}.exe", "{{.Vars}} {{.Script}}"]
  script          = "scripts/windows/cleanup.ps1"
}

后处理PowerShell脚本

param(
    [string]
    $TemplateName = $env:TEMPLATE_NAME
)
Write-Host $TemplateName

控制台错误日志

==> vsphere-iso.windows-server-standard-dexp (shell-local): Running local shell script: scripts/windows/cleanup.ps1
    vsphere-iso.windows-server-standard-dexp (shell-local): ERR_ID_NOT_IMPLEMENTED_BY_BUILDER

解决方案

vsphere-iso构建器目前并未实现build.ID变量,官方文档的描述存在偏差。可通过以下两种可靠方式解决:

  1. 复用预定义的VM/模板名称
    如果在vsphere-iso构建器配置中已经明确指定了vm_name(例如vm_name = var.template_name),直接在后处理器中引用该变量即可:

    "TEMPLATE_NAME=${var.template_name}",
    
  2. 提前在local变量中定义动态名称
    若VM名称是动态生成的(比如带时间戳),先在locals块中统一定义,再同时用于构建器和后处理器:

    locals {
      vm_template_name = "windows-server-template-${timestamp()}"
    }
    
    # 构建器中引用
    source "vsphere-iso" "windows-server" {
      vm_name = local.vm_template_name
      # 其他配置项...
    }
    
    # 后处理器中引用
    post-processor "shell-local" {
      environment_vars = [
        # ...其他环境变量
        "TEMPLATE_NAME=${local.vm_template_name}",
      ]
      # 其他配置项...
    }
    

这种方式能保证前后使用的VM名称完全一致,彻底避开未实现的build.ID变量。

内容的提问来源于stack exchange,提问作者Jamie O'Connell

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 18:05:29