Here are three separate ways of using Ansible to perform system upgrades on an Ubuntu based system.
apt-update-upgrade.ymlThis is the absolute most basic playbook I use. It performs anapt update, thenapt full-upgradeand lastly anapt autoremoveandapt autoclean.apt-update-upgrade-only-once-a-day.ymlI use this in playbook where I'm repeatedly running it to do installs or reconfiguration, or where I haveunattended-upgradesinstalled.apt-update-upgrade-with-check.ymlOn systems where I'm not the only administrator, I don't always know whether I'll want to apply an upgrade, so this gives me a chance to list off what packages will be updated and upgraded when I let it proceed... or perhaps I just want a list of what's going to change first! To run this, I also need to create a directory in the same path calledfilter_pluginsand need to put the filesplitpart.pyin there (that's from https://www.redpill-linpro.com/sysadvent/2017/12/24/ansible-system-updates.html).
Anyway, I use these in different places for different purposes, so I hope they help you!