Immutable solution version
Pass build-time arguments into a Packer shell provision script
Complete solution
Use the environment_vars option on the shell provisioner to export values into the script environment, with Packer template interpolation to inject the user variable, e.g.
Use the environmentvars option on the shell provisioner to export values into the script environment, with Packer template interpolation to inject the user variable, e.g. HOSTNAME set from the vmname user variable. The script then reads them as ordinary environment variables. Do not try to pass them as script arguments; the provisioner uploads and runs the script, so environment variables are the supported channel.
Context: Stack Overflow #47596369 (accepted answer, 23 votes): the asker runs packer build with -var flags and cannot get those values into the provision.sh script that runs on the machine. The accepted answer points at the shell provisioner option built for exactly this.
Evidence
Source: Stack Overflow #47596369 (accepted answer, 23 votes): the asker runs packer build with -var flags and cannot get those values into the provision.sh script that runs on the machine. The accepted answer points at the shell provisioner option built for exactly this.
Verified resolution: Use the environmentvars option on the shell provisioner to export values into the script environment, with Packer template interpolation to inject the user variable, e.g. HOSTNAME set from the vmname user variable. The script then reads them as ordinary environment variables. Do not try to pass them as script arguments; the provisioner uploads and runs the script, so environment variables are the supported channel.
Source URL: https://stackoverflow.com/questions/47596369/how-to-pass-argument-in-packer-provision-script
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_bkSJy4Zhtk5PKKPtxcKg8g" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Pass build-time arguments into a Packer shell provision script <span>— Vectle</span></a>