AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible yum Module: Install Packages on RHEL/CentOS (Examples & Playbook) — Video Tutorial

How to install packages on RHEL, CentOS, Fedora, and AlmaLinux using Ansible yum module. Install, update, remove packages with state, enablerepo, and version.

Watch on YouTube · Read the written article

Tutorial summary

What you'll learn

  • How to Install a package with Ansible in RedHat-like systems?
  • Ansible Install a package in RedHat-like systems
  • Main Parameters
  • Demo
  • single package
  • specific package version
  • Conclusion
  • Package Installation Examples
  • Install specific version
  • Install multiple packages
How to Install a package with Ansible in RedHat-like systems? I’m going to show you a live Playbook and some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot Ansible Install a package in RedHat-like systems Today we’re talking about the Ansible module YUM and DNF. The full names are `ansible.builtin.yum` and `ansible.builtin.dnf`, which means are part of the collection of modules “builtin” with ansible and shipped with it. These modules are pretty stable and out for years. They work on RedHat-like operating systems and Manages packages with the yum/DNF package manager. For compatibility purpose you probably ended up using more the yum module than the DNF one, that is designed for modern operating systems. Main Parameters - name _string_ - state _string_ - update_cache _boolean_ - allow_downgrade _boolean_ The parameter list is pretty wide but this four are the most important options. In the “name” parameter you are going to specify the name of the package or the specific version you would like to install. The “state” specifies the action that we would like to perform. In our case for install is “present or installed”. I’d like to mention some additional parameters that might be useful for you. For example “update_cache” forces to update the repository metadata before the installation. It could be useful to make sure that the repository is up-to-date. “allow_downgrade” is an interesting option that allows you to install a previous version of a package currently installed (the downgrade process), default disabled. Demo Let’s jump in a real-life playbook to install a package in RedHat-like systems with Ansible single package - package install ```yaml --- - name: yum module Playbook hosts: all become: true tasks: - name: install package yum: name: wget state: present ``` specific package version - specific package version ```yaml --- - name: yum module Playbook hosts: all become: true tasks: - name: install package yum: name: wget-1.19.5-7.el8 state: present allow_downgrade: true ``` [code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/tree/master/install%20a%20package%20in%20RedHat-like%20systems) Conclusion Now you know how to install a package and a specific version of a package in RedHat-like systems. Package Installation Examples Install specific version ```yaml - name: Install specific nginx version ansible.builtin.yum: name: nginx-1.24.0-1.el9 state: present become: true ``` Install multiple packages ```yaml - name: Install development tools ansible.builtin.yum: name: - git - vim-enhanced - curl - wget - jq state: present become: true ``` Install from a specific repo ```yaml - name: Install from EPEL ansible.builtin.yum: name: htop state: present enablerepo: epel become: true ``` Install from URL or local RPM ```yaml - name: Inst

About this tutorial

  • Author: Luca Berton
  • Difficulty: Beginner
  • Read time: 4 min
  • Category: installation

Topics covered

Related video tutorials