Open In App

How to Install rpm Package in Linux Using Ansible ?

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.



They are two working methods in ansible

  1. Ad-hoc
  2. 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

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:

ssh -i  "keypair-pem file" ec2-user@<instance-public-ip address>compute-1.amazonaws.com

Step 2: Installing Ansible

sudo amazon-linux-extras install ansible2

Step 3: Hosts File Configuration

sudo vi /etc/ansible/hosts

[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

ansible all -m ping

Step 5: Create a file for playbook

sudo vi playbook.yml

---
- name: Install RPM package using Ansible
hosts: localhost
become: yes
tasks:
- name: Install RPM using Yum
yum:
name: "rpm"
state: present

ansible-playbook <playbook_filename> --syntax-check

Step 6: Run or execute the playbook

ansible-playbook playbook.yml

Step 7: Ensure the rpm package installation

ansible localhost -m -a "rpm --version"

Installation Of rpm Packages In Linux Using Ansible – FAQs

What is Ansible?

Ansible is a Orchestration, configuration management tool (installation and deployment). Ansible is a suite of software tools that enables to configure systems,deploy software and orchestrate advanced workflows to support application deployment,system updates and more……it is automation tool that can be used to mange large group of computer systems.

we can manage and configure of other servers called slave servers from a single server called Master server.

Where can we configure the hosts file or Inventory Path?

we can configure the hosts file.Before we create a basic configuration, I want to take a moment to explain the Ansible file/folder structure. You’ll note that if you list the files/folders in /etc/ansible that you’re presented with the following.

/etc/ansible/hosts
sudo vi /etc/ansible/hosts

Is Ansible Agent-based or Agentless?

Ansible is primarily agentless, meaning that it does not require any software to be installed on target hosts. Instead, Ansible uses SSH (or other connection methods) to communicate with remote hosts and execute tasks. This agentless architecture simplifies deployment and reduces overhead.

How many working methods in Ansible?

There are two working methods in ansible

1.Ad-hoc: 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.

2.playbook: Ansible uses a simple YAML syntax called “playbooks” to describe automation tasks and configurations.


Article Tags :