Virtualbox-iso no tty present and no askpass program specified

I’m reasonably new to packer but not new to Hashicorp, as I’ve been using VirtualBox and Terraform for a while now. I’m attempting to get an OVA created using the virtualbox-iso builder, configured my JSON builder file (which passes validation) and using a pretty basic preseed file to install Ubuntu 18 (using the preseed ISO, not live), I start my build.

The main Ubuntu install appears to work just fine (I have my preseed file installing openssh-server) but at the end of the build, I get the following message:

==> virtualbox-iso: sudo: no tty present and no askpass program specified

Now from what I’ve seen, this is because I need to add my default SSH user into the sudoers with a no password option, which is fine - however, I’m not sure how to do that.

I’ve tried adding a shell provisioner and pointing to a local script that adds a .conf file to /etc/sudoers.d/ : it appears to do something (I get a connect to SSH message) but then the no tty present error:

==> virtualbox-iso: Using ssh communicator to connect: 127.0.0.1
==> virtualbox-iso: Waiting for SSH to become available...
==> virtualbox-iso: Connected to SSH!
==> virtualbox-iso: Uploading VirtualBox version info (5.2.42)
==> virtualbox-iso: Provisioning with shell script: postInstallScript
==> virtualbox-iso: sudo: no tty present and no askpass program specified

I’ve even tried taking out and having no provisioner … I get the same no tty present error.

Obviously, due to these errors, I’m not even getting the OVA that I’m hoping packer creates for me, as it cleans up automatically.

Can someone give me some guidance please?!

I’ve had this error, too, and I think using sudo this way, did it:

    {
      "type": "shell",
      "execute_command": "chmod +x {{ .Path }}; echo '{{ user `vm_setup_password` }}' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'",
      "pause_before": "15s",
      "scripts" : [
        "{{ user `packer_provisioners_dir` }}/{{ user `vm_distribution_name` }}/{{ user `vm_distribution_release` }}/baseline.sh",
        "{{ user `packer_provisioners_dir` }}/{{ user `vm_distribution_name` }}/{{ user `vm_distribution_release` }}/puppet.sh",
        "{{ user `packer_provisioners_dir` }}/{{ user `vm_distribution_name` }}/{{ user `vm_distribution_release` }}/cleanup.sh",
        "{{ user `packer_provisioners_dir` }}/common/zerodisk.sh"
      ]
    },

Which file is this please??