Last Updated on 4 hours by Sachin G
Managing software packages across multiple Linux systems can be challenging, especially in environments that require automation, consistency, and speed. That’s where Ansible yum module becomes a vital tool. In this blog post, we’ll explore how to use Ansible for Linux updates, installations, and package version control with Ansible, specifically using the ansible.builtin.yum
module.
What is ansible.builtin.yum
?
ansible.builtin collection included default yum or dnf module that managed package operations on the managed host. The ansible.builtin.yum module is part of the core Ansible modules for system updates and is used to manage software packages on RHEL, CentOS, and other YUM-based distributions. The ansible. builtin.yum module serves as a connection between the playbook and the YUM package manager. which is the default package management utility for RPM-based Linux operating systems like CentOS, AlmaLinux, Rocky, Oracle Linux, etc. It supports install RPM with Ansible, updating packages, removing them, and even handling Yum Repository Management. This module enabled users to perform a variety of package-related operations, including installation, removal, and updating across multiple systems.
I have explained How Ansible Navigator and the Ansible execution environment can install. Click here to read more.
Before working on the yum or dnf module, you can check the description or attributes through the following command and how to use this module in the example section.
ansible-navigator doc ansible.builtin.yum
ansible-doc ansible.builtin.yum
You can add the -s option will show attributes before the doc then it will show only attribute information.
Basic Structure of the Yum Module in Ansible
Here’s a simple playbook for yum install:
The usage of ansible. builtin.yum ro ansible.builtin.dnf the module follows a simple and intuitive syntax within Ansible playbooks.
- name: Install package hosts: host_pattern tasks: - name: Install httpd package ansible.builtin.yum: name: package_name ( eg httpd ) state: present
In this Ansible Playbook, the state
parameter defines the desired outcome (e.g., present
, absent
). It supports idempotent operations across all target systems.
In this example, the playbook instructs Ansible to install the Apache web server package (httpd) on remote hosts designated as web servers.
The ansible.builtin.yum or ansible.builtin.dnf module empowers administrators and DevOps practitioners to streamline package management tasks within their infrastructure.
Package Installation, Removal & Updates
The yum module supports full package management with Ansible. Here are common examples:
Install Packages Using Ansible
- name: Install multiple packages
ansible.builtin.yum:
name:
- vim
- curl
- wget
state: present
Ansible Remove Package
- name: Remove a package
ansible.builtin.yum:
name: vsftpd
state: absent
Update Yum Package Ansible
- name: Update all packages
ansible.builtin.yum:
name: "*"
state: latest
This also fits into use cases like bulk server patching, security updates automation, and multi-node synchronization.
I’m Sachin Gupta — a freelance IT support specialist and founder of Tech Transit. I’m certified in Linux, Ansible, OpenShift (Red Hat), cPanel, and ITIL, with over 15 years of hands-on experience. I create beginner-friendly Linux tutorials, help with Ansible automation, and offer IT support on platforms like Upwork, Freelancer, and PeoplePerHour. Follow Tech Transit for practical tips, hosting guides, and real-world Linux expertise!