How to use the apt module with ansible ?

Xavier Pestel (Xavki)
1 min readDec 30, 2020

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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Xavier Pestel (Xavki)
Xavier Pestel (Xavki)

Written by Xavier Pestel (Xavki)

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

No responses yet

Write a response