When a package update brings a new version of a config file you changed, dpkg stops and asks what to do. In a script or over a flaky SSH session, that question hangs everything.
Tell dpkg the answer in advance:
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" upgrade
--force-confold keeps your current file when you changed it and the package’s version changed too. Adding --force-confdef makes dpkg take the default action where there is one, which for files you never touched means quietly installing the new version. DEBIAN_FRONTEND=noninteractive silences the debconf questions some packages ask, which is a separate kind of prompt.
This is the combination I’d use for automated upgrades of servers where config lives in version control or Ansible.
Keeping the old file has a price. The new default config from the package is saved next to yours as .dpkg-dist, and new settings in it don’t reach you. Every now and then it is worth looking for them:
find /etc -name '*.dpkg-dist' -o -name '*.dpkg-new'
Compare them with your files, take over what matters and delete the leftovers. Otherwise an option that the new version needs may be missing from your config for years.
Further reading: dpkg(1) manual page (–force-confold), apt.conf(5) manual page