Command line for System Upgrades

I am working on patching multiple ubuntu systems and have run into an issue and I am unable to find a solution. I’m pretty new to ansible so not sure if it’s possible to respond to prompts by OS.

Here is what I run now:

ansible <host_group> -m shell -s -a “apt-get upgrade -y” -u -k -K

This works for apt-get update
apt-get install --only-upgrade

This issue on the upgrade on these systems:

  1. There are 5 points during the upgrade that require response with enter on a y/n answer and a No prompt for PAM.

Is there a way do do this via command line.

I would try using the apt module first. If that does not deal with it as you want it to, I would use debconf + apt or if you insist on using direct commands, the expect module.