How to Install rpm Package in Linux Using Ansible ?
Last Updated :
23 Jul, 2025
Ansible, a strong computing automation tool, expands its capabilities beyond configuration management to package management, including the installation of RPM packages on Linux frameworks.RPM (Red Hat Package Manager) is a package management system executives framework utilized by different Linux distributions, including Red Hat Enterprise Linux (RHEL), CentOS, and Fedora. Ansible improves on the method involved with managing RPM packages across multiple hosts by providing a declarative and idempotent approach. Ansible abstracts away the complexities of RPM package management, allowing clients to focus on defining the desired state of their frameworks as opposed to the perplexing details of package installation.
While deploying applications, managing libraries, or guaranteeing framework consistency, Ansible smoothes out the establishment lifecycle making it effective repeatable, and adaptable.
In this guide, we will explore how to use Ansible to install RPM packages on Linux systems, empowering administrators to maintain framework trustworthiness and effectiveness easily.
What is Ansible?
Ansible is an Orchestration, and configuration management tool (installation and deployment). Ansible is a suite of software tools that enables configuring systems, deploying software, and orchestrating advanced workflows to support application deployment, system updates, and more. It is an automation tool that can be used to manage large groups of computer systems.
- we can manage and configure other servers called slave servers from a single server called the Master server.
- when we install Ansible in the master server a file is created called Hosts also known as the inventory path inside this inventory path we give details of slave servers such as IP address, key pair path, and hostnames. with this, we create a bridge between slave and master to manage configuration.

They are two working methods in ansible
- Ad-hoc
- Playbook
What Are Ansible Ad-hoc Commands ?
An ansible Ad-hoc command uses the /usr/bin/ansible command-line tool to automate a single task on one or more managed nodes/slave servers these commands are quick and easy but not reusable.
Ad-hoc command are perfect for tasks you repeat rarely.for example you want to drive off all the machines in your working environment for pongal vacation you could execute quick one-line command in ansible without composing a playbook. This ad-hoc command can be written as
ansible [pattern] -m(module) command -a(argument) "parameters"
What Is Ansible Playbook?
At its core, Ansible uses a simple YAML syntax called "playbooks" to describe automation tasks and configurations. completely different way to use ansible than in ad-hoc task execution mode and are particularly powerful. These playbooks define a series of steps or "plays" in that play we divide the plays with tasks. Ansible executes on target hosts, allowing users to define the desired state of their infrastructure in a declarative manner.
Example For Playbook
- name: Install and start Nginx
hosts: web_servers
become: yes
tasks:
- name: Install Nginx package
yum:
name: nginx
state: present
- name: Ensure Nginx service is running
service:
name: nginx
state: started
enabled: yes
Key Terminologies Of Ansible
- Agentless: By the inventory path or hosts file we shall make the ansible agentless. Ansible operates over SSH, making it agentless and eliminating the need to install any additional software on target hosts. This simply deployment and reduces overhead.
- Idempotent: Ansible ensures that the system's state matches the desired state defined in the playbook, regardless of the system's current state. This makes automation tasks predictable and repeatable.
- Extensible: Ansibles' modular architecture allows users to extend its functionality through custom modules and plugins, enabling integration with a wide range of systems, tools, and services.
- Infrastructure as Code (IaC): With this Infrastructure as a code IaC feature we can create any cloud environment. Ansible enables Infrastructure as Code practices by allowing users to define infrastructure configurations in human-readable YAML files. This approach promotes version control, collaboration, and repeatability.
How to Install rpm package In Linux using Ansible: A step by step guide
Here, we are going to install rpm package in Linux using ansible in aws EC2 instance.
Step 1 : Create an AWS account and navigate to EC2 and select launch instance.
Launch An Instance With Configuration:
- AMI- amazon Linux 2
- instance type- t2.micro
- Security group- allow SSH(22),HTTP(80),HTTPS(443) traffic from anywhere
- Configure storage - 8gb with root volume type gp2
- Connect this instance with any CLI terminal by using SSH
ssh -i "keypair-pem file" ec2-user@<instance-public-ip address>compute-1.amazonaws.com

Step 2: Installing Ansible
- install Ansible with amazon-linux-extras and the version of ansible is 2.9.23.
sudo amazon-linux-extras install ansible2

Step 3: Hosts File Configuration
- After installing and setup the ansible a hosts file is created called inventory path in /etc/ansible path
- This file holds information for the hosts/and host groups you will configure
- we need to configure this file called hosts
sudo vi /etc/ansible/hosts

- Now,configure this inventory hosts file with slave server's details such as server name,ansible_host,ansible_user, ansible_ssh_private_key_file path
- for this create one group name as [localhost] you can configure this group name as you wish.
- below this group localhost we add the slave server details.
- the keypair pem file should be only with read permissions to root.
[localhost]
slave ansible_host=172.31.45.95 ansible_user=ec2-user ansible_ssh_private_key_file path=/home/ec2-user/11.pem

Step 4: Check the connection to the slave server
- now we need to check the connection to this slave server wit the ping module
ansible all -m ping

Step 5: Create a file for playbook
- to write a playbook we need to create file for this playbook
sudo vi playbook.yml

- in this file write the playbook
- You need to make sure that you follow standard YAML syntax guidelines when manipulating Ansible configuration files, otherwise you are likely to experience syntax errors. A link to YAML Syntax on Ansible’s website is included in the resources section of this article.
---
- name: Install RPM package using Ansible
hosts: localhost
become: yes
tasks:
- name: Install RPM using Yum
yum:
name: "rpm"
state: present

- you can check the playbook syntax error
ansible-playbook <playbook_filename> --syntax-check
Step 6: Run or execute the playbook
- execute the playbook file playbook.yml which has yaml script.
ansible-playbook playbook.yml

- playbook is successfully executed.
Step 7: Ensure the rpm package installation
- we need to make sure the rpm package is successfully installed or not
- we can check the rpm installation and its version from this ansible by using ad-hoc command.
ansible localhost -m -a "rpm --version"
Similar Reads
DevOps Tutorial DevOps is a combination of two words: "Development" and "Operations." Itâs a modern approach where software developers and software operations teams work together throughout the entire software life cycle.The goals of DevOps are:Faster and continuous software releases.Reduces manual errors through a
7 min read
Introduction
What is DevOps ?DevOps is a modern way of working in software development in which the development team (who writes the code and builds the software) and the operations team (which sets up, runs, and manages the software) work together as a single team.Before DevOps, the development and operations teams worked sepa
10 min read
DevOps LifecycleThe DevOps lifecycle is a structured approach that integrates development (Dev) and operations (Ops) teams to streamline software delivery. It focuses on collaboration, automation, and continuous feedback across key phases planning, coding, building, testing, releasing, deploying, operating, and mon
10 min read
The Evolution of DevOps - 3 Major Trends for FutureDevOps is a software engineering culture and practice that aims to unify software development and operations. It is an approach to software development that emphasizes collaboration, communication, and integration between software developers and IT operations. DevOps has come a long way since its in
7 min read
Version Control
Continuous Integration (CI) & Continuous Deployment (CD)
Containerization
Orchestration
Infrastructure as Code (IaC)
Monitoring and Logging
Microsoft Teams vs Slack Both Microsoft Teams and Slack are the communication channels used by organizations to communicate with their employees. Microsoft Teams was developed in 2017 whereas Slack was created in 2013. Microsoft Teams is mainly used in large organizations and is integrated with Office 365 enhancing the feat
4 min read
Security in DevOps