Ansible Pilot

Install a package in RedHat-like systems - Ansible module yum

Some real-life examples of how to install a package and a specific version of a package in RedHat-like systems: RedHat Enterprise Linux, CentOS, CentOS Stream, Fedora, ClearOS, Oracle Linux, EuroLinux, Fermi Linux, EulerOS, ROSA Linux, Springdale Linux, Asianux

How to Install a package with Ansible in RedHat-like systems?

I’m going to show you a live demo 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

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


---
- name: yum module demo
  hosts: all
  become: true
  tasks:
    - name: install package
      yum:
        name: wget
        state: present

specific package version

---
- name: yum module demo
  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

Recap

Now you know how to install a package and a specific version of a package in RedHat-like systems. Subscribe to the YouTube channel, Medium, Website and Twitter to not miss the next episode of the Ansible Pilot.

Academy

Learn the Ansible automation technology with some real-life examples in my

Want to keep this project going? Please donate

Trustpilot
Follow me

Subscribe not to miss any new releases

August 5, 2021

FREE Top 10 Best Practices

Top 10 Best Practices of Ansible Automation: save time, reduce errors and stress