如何使用加壳器export_opts?

How to use packer export_opts?

我使用 Packer and I would like to set some VM meta data (e.g. description, version) using the export_opts parameter. The docs say

构建了一个 VirtualBox VM

export_opts (array of strings) - Additional options to pass to the VBoxManage export. This can be useful for passing product information to include in the resulting appliance file.

我正在尝试在 bash 脚本调用加壳器中执行此操作:

desc=' ... some ...'
desc+=' ... multiline ...'
desc+=' ... description ...'
# this is actually done using printf, shortened for clarity
export_opts='[ "version", "0.2.0", "description", "${desc}" ]'

# the assembled string looks OK
echo "export_opts: ${export_opts}"

packer build \
        ... (more options) ...
    -var "export_opts=${export_opts}"             \
        ... (more options) ...
    <packer configuration file>

我也试过 --version 而不是 version 并将 version 和值放入同一个字符串中,但是 none 有效;导出并重新导入后,VM 描述为空。

有没有人有一些可用的示例代码或者可以帮助我解决我做错了什么?

非常感谢。

更新:

之后,我发现添加

"export_opts": [ "--vsys", "0", "--version", "0.2.0", "--description", "some test description" ],

到 Packer JSON 文件确实有效;将与 --var 相同的字符串传递给 Packer 不起作用。

您可能必须将数据指定为

在你的加壳器 json 文件中

  "export_opts": [ "--vsys 0 --version \"0.2.0\"", "{{.Name}} --description \"${desc}\" " ],

终于解决了这个问题,用下面的例子更新了加壳文档,pull requests待定:

Packer JSON 配置文件示例:

{
  "type": "virtualbox-ovf",
  "export_opts":
  [
    "--manifest",
    "--vsys", "0",
    "--description", "{{user `vm_description`}}",
    "--version", "{{user `vm_version`}}"
  ],
  "format": "ova",
}

VirtualBox VM description 可能包含任意字符串; GUI 解释 HTML 格式。但是,JSON 格式不允许在一个值内任意换行。通过在打包程序调用之前准备 shell 中的字符串来添加多行描述(shell > 连续字符被截断以便于复制和粘贴):

vm_description='some
multiline
description'

vm_version='0.2.0'

packer build \
    -var "vm_description=${vm_description}" \
    -var "vm_version=${vm_version}"         \
    "packer_conf.json"