Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Packer using default variables?

Tags:

vagrant

packer

I've been trying to figure out the possibility of using option vars in packer, my script is as follows:

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

Were a typical command would be:

packer build              \
    -var 'config=master'  \
    template.json

But also be able to just do the following:

packer build template.json # were config would default to slave
like image 284
ehime Avatar asked Jul 28 '26 22:07

ehime


1 Answers

Command line variables override settings in your json templates. See Packer's documentation: https://www.packer.io/docs/templates/user-variables.html

So just set the default value in the template and override with the command line example you were already using.

Your template would be:

"provisioners": [{
   "type": "shell",
   "scripts": [
      "scripts/centos/5.11/puppet-{{user `config`}}.sh"
   ]
}],
"variables": {
  "config": "slave"
} 
like image 121
Brian Whipple Avatar answered Aug 02 '26 20:08

Brian Whipple



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!