我一直试图找出在打包机中使用期权变量的可能性, 我的脚本如下:
"provisioners": [{
"type": "shell",
"scripts": [
"scripts/centos/5.11/puppet-{{user `config`}}.sh",
]
}],
"variables": {
"config": "{{user `type`}} | slave",
}
典型的命令是:
packer build \
-var 'config=master' \
template.json
但也可以做到以下几点:
packer build template.json # were config would default to slave
答案 0 :(得分:8)
命令行变量会覆盖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"
}