How to use the apt module with ansible ?

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
apt:
update_cache: yes
cache_valid_time: 3600

Or if you have a package to install it :

- name: install haproxy in stretch-backports
apt:
name: haproxy
default_release: stretch-backports
update_cache: yes
cache_valid_time: 3600

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.

Credits : https://wallhaven.cc/w/n66j67

In other videos we’ll see how to add repositories with the specific module.

My ansible tutorials here

Microservices architecture and opensource. I’m maintainer of xavki https://youtube.com/c/xavki-linux about opensource. My blog : https://xavki.blog/