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. HOSTNAME set from the vm_name 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.