3

パッカーでオプション変数を使用する可能性を理解しようとしてきました。私のスクリプトは次のとおりです。

"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
4

1 に答える 1

10

コマンド ライン変数は、json テンプレートの設定をオーバーライドします。パッカーのドキュメントを参照してください: https://www.packer.io/docs/templates/user-variables.html

したがって、テンプレートにデフォルト値を設定し、既に使用しているコマンド ラインの例で上書きするだけです。

テンプレートは次のようになります。

"provisioners": [{
   "type": "shell",
   "scripts": [
      "scripts/centos/5.11/puppet-{{user `config`}}.sh"
   ]
}],
"variables": {
  "config": "slave"
} 
于 2015-01-06T05:53:11.117 に答える