Packer使用默认变量?

ehi*_*ime 3 packer vagrant

我一直试图弄清楚在packer中使用选项变量的可能性,我的脚本如下:

"provisioners": [{
  "type": "shell",
  "scripts": [
    "scripts/centos/5.11/puppet-{{user `config`}}.sh",
  ]
}],
"variables": {
  "config": "{{user `type`}} | slave",
} 
Run Code Online (Sandbox Code Playgroud)

一个典型的命令是:

packer build              \
    -var 'config=master'  \
    template.json
Run Code Online (Sandbox Code Playgroud)

但也能够做到以下几点:

packer build template.json # were config would default to slave
Run Code Online (Sandbox Code Playgroud)

小智 9

命令行变量会覆盖json模板中的设置.请参阅Packer的文档:https://www.packer.io/docs/templates/user-variables.html

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

你的模板是:

"provisioners": [{
   "type": "shell",
   "scripts": [
      "scripts/centos/5.11/puppet-{{user `config`}}.sh"
   ]
}],
"variables": {
  "config": "slave"
} 
Run Code Online (Sandbox Code Playgroud)