For beginners, I explain in a playlist how to use ansible. In this tutorial, I show you the apt module for debian servers. This module is very useful to install and remove packages. But you can use it to do upgrades and some other parameters. If you want to learn ansible you can follow this video.
If you just want to update the apt cache, you can do it with this task :
- name: update the cache
Or if you have a package to install it :
- name: install haproxy in stretch-backports
In this case we add a cache valid time to one hour. That will prevent you from updating the cache on each run. And you can specify the release to not use the default version.
In other videos we’ll see how to add repositories with the specific module.
My ansible tutorials here