No tty present and no askpass program specified

Hello,

I’m been learning how to use Packer this week on my home lab where I have an ESXi 7 host.

I’m simply trying to deploy a Ubuntu 18.04 VM however at the end of the build I get this error in the packer console:

sudo: no tty present and no askpass program specified

This is what I have done.

Build.json
Preseed.cfg
variables.json

Command I run:

sudo packer build -var-file=variables.json build.json

In ESXi I see the VM build and complete and reboot and it gets an IP and I get a SSH prompt briefly before Packer deletes the VM after I see the above message.

This is the full error:

==> Ubuntu-18.04: Connecting to VNC over websocket...
==> Ubuntu-18.04: Waiting 10s for boot...
==> Ubuntu-18.04: Typing the boot command over VNC...
==> Ubuntu-18.04: Waiting for SSH to become available...
==> Ubuntu-18.04: Connected to SSH!
==> Ubuntu-18.04: Provisioning with shell script: /tmp/packer-shell382031289
==> Ubuntu-18.04: sudo: no tty present and no askpass program specified
==> Ubuntu-18.04: Provisioning step had errors: Running the cleanup provisioner, if present...
==> Ubuntu-18.04: Stopping virtual machine...
==> Ubuntu-18.04: Destroying virtual machine...
Build 'Ubuntu-18.04' errored after 8 minutes 21 seconds: Script exited with non-zero exit status: 1.Allowed exit codes are: [0]

==> Wait completed after 8 minutes 21 seconds

==> Some builds didn't complete successfully and had errors:
--> Ubuntu-18.04: Script exited with non-zero exit status: 1.Allowed exit codes are: [0]

==> Builds finished but no artifacts were created.

What am I doing wrong?

"provisioners": [
  {
    "type": "shell",
    "pause_before": "30s", 
    "inline": [
        "echo '{{ user `ssh_password` }}' | sudo -S sh -c 'apt-get update -y'"
    ]
  }
]

In the best case scenario, you pack everything into a script:

"provisioners": [
  {
    "type": "shell",
    "execute_command": "chmod +x {{ .Path }}; echo '{{ user `ssh_password` }}' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'",
     "pause_before": "30s",
     "scripts" : [
       "baseline.sh"
     ]
  }
] 
1 Like

Thanks for you reply this worked for me thanks. What is the difference between “shell” and “shell-local” which I have seen in other examples?

shell-local is executed on your machine executing the packer binary/ build and shell is executed on the template machine/ image.