How to fix debconf: unable to initialize frontend: Dialog error?

I am using the vsphere-iso builder to build an Ubuntu-18.04 VM and a shell provisioner and when I run either of the following two commands:

sudo apt-get install software-properties-common --yes
sudo apt-get install ca-certificates curl gnupg lsb-release --yes

I get these errors below:

==> vsphere-iso.ubuntu-18_04-base-template: debconf: unable to initialize frontend: Dialog
==> vsphere-iso.ubuntu-18_04-base-template: debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.)
==> vsphere-iso.ubuntu-18_04-base-template: debconf: falling back to frontend: Readline
==> vsphere-iso.ubuntu-18_04-base-template: debconf: unable to initialize frontend: Readline
==> vsphere-iso.ubuntu-18_04-base-template: debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7, <> line 31.)
==> vsphere-iso.ubuntu-18_04-base-template: debconf: falling back to frontend: Teletype
==> vsphere-iso.ubuntu-18_04-base-template: dpkg-preconfigure: unable to re-open stdin:

Googling for this issue I find many who say that setting DEBIAN_FRONTEND=noninteractive fixes the issue however that has not fixed the issue for me.

I know I can pipe errors to /dev/null but I’d rather not do that in case errors that break the build happen. I’d like to actually stop the error from occurring, such as setting DEBIAN_FRONTEND to noninteractive was supposed to do.

Does anyone know how to fix this?
It is not stopping the build but I would like to

we are using

  provisioner "shell" {
    inline = [
      "echo set debconf to Noninteractive", 
      "echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections" ]
  }

to get rid of that message

Thanks @joerg.lang! — I will give that a try and report back.