Vagrant 使用默认变量的打包器?

Vagrant 使用默认变量的打包器?,vagrant,packer,Vagrant,Packer,我一直在想在packer中使用选项变量的可能性, 我的脚本如下: "provisioners": [{ "type": "shell", "scripts": [ "scripts/centos/5.11/puppet-{{user `config`}}.sh", ] }], "variables": { "config": "{{user `type`}} | slave", } 典型的命令是: packer build \ -va

我一直在想在packer中使用选项变量的可能性, 我的脚本如下:

"provisioners": [{
  "type": "shell",
  "scripts": [
    "scripts/centos/5.11/puppet-{{user `config`}}.sh",
  ]
}],
"variables": {
  "config": "{{user `type`}} | slave",
} 
典型的命令是:

packer build              \
    -var 'config=master'  \
    template.json
"provisioners": [{
   "type": "shell",
   "scripts": [
      "scripts/centos/5.11/puppet-{{user `config`}}.sh"
   ]
}],
"variables": {
  "config": "slave"
} 
但也能做到以下几点:

packer build template.json # were config would default to slave

命令行变量覆盖json模板中的设置。见包装商文件:

因此,只需在模板中设置默认值,并使用您已经使用的命令行示例进行覆盖

您的模板将是:

packer build              \
    -var 'config=master'  \
    template.json
"provisioners": [{
   "type": "shell",
   "scripts": [
      "scripts/centos/5.11/puppet-{{user `config`}}.sh"
   ]
}],
"variables": {
  "config": "slave"
}