3

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
ehime
  • 8,025
  • 14
  • 51
  • 110

1 Answers1

10

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"
} 
Brian Whipple
  • 166
  • 1
  • 4