CertGrid CertGrid
Hands-on Lab·Ansible

Ansible Package Management

Package management is the most common thing a playbook does. There is a generic module that works anywhere and a specific one with all the options, a list form that is much faster than a loop, and a `state` that quietly makes your playbook non-idempotent. This covers all four, and how to ask a host what it has.

Automating Administration Guide 29 of 45 Beginner

Written against the versions above. This lab is Ubuntu 26.04 and EX294 is a RHEL exam. `ansible.builtin.apt` here is `ansible.builtin.dnf` there, and `apt_repository` is `yum_repository`. `ansible.builtin.package` works on both by dispatching on `ansible_pkg_mgr`, at the cost of the distribution-specific options.

One managed node. Packages are installed and removed again at the end.
Server NameIP AddressOSRolesCPURAMHDD
ANS-CTL01192.168.0.36Ubuntu 26.04 LTSAnsible Control Node2 Core3 GB50 GB
ANS-A01192.168.0.37Ubuntu 26.04 LTSManaged Node (group: web)2 Core3 GB50 GB

Before you start

  1. The configuration this guide assumes

  2. Install something, twice

  3. The generic module versus the specific one

  4. Several packages at once

  5. Asking what is installed

Official sources