Open In App

How To Install PIP Using Ansible ?

Nowadays the IT culture is evolving with Agile practices and DevOps Culture, on idea of making the business plans, and features quickly to market and making users available. In this software development workflow configuring software and updating the patches to each system manually or through automation is time-consuming. In resolving this kind of problem ansible comes into play. Ansible works agentless with push-based mechanism that facilitates configuring the worker nodes that are connected to it remotely with the help of playbooks and ad-hoc commands.

Understanding Of Primary Terminologies

How To Install pip Using Ansible Playbook: A Step-By-Step Guide

In this implementation we taking 3 aws instances with Amazon linux AMI, (you can also choose other AMI also) as One Manager Node and 2 Worker Nodes. Here we define the details and credentials in inventory and install the pip software in worker nodes through running the playbook for it in manager node.



Step 1: Create Instances

Navigate To AWS Management Console and sign with your Credentials.

Navigate To EC2 Dashboard And Click On Launch Instances.



Step 2: Configure SSH Key And Security Groups

Choose The available key pair in your PC, if you don’t have create one pem file. Make sure the choosen pem file available in your local laptop.

Step 3: Running Instances

Step 4: Connect Manager Node

Step 5: Connect EC2 Console

Step 6: Install Ansible

yum install ansible -y

Step 7: Verify Ansible

ansible --version

Step 8: Copy Pem file

Step 9: Adding Permission To Pem File

chmod 400 myssh_key.pem

Step 10: Create Inventory

Step 11: Ping The Worker Nodes

ansible -i hosts all -m ping

ansible -i hosts all -m -o ping

Step 12: Define Playbook

---
- name: Install pip on Amazon Linux
hosts: your-instance-public-ip
become: true
tasks:
- name: Update package cache
yum:
name: '*'
state: latest
become: true

- name: Install Python and pip
yum:
name: "{{ item }}"
state: present
become: true
loop:
- python3
- python3-pip

Step 13: Run The Playbook

ansible-playbook -i hosts myplaybook.yml 

Step 14: Verify The Software In Worker Nodes

To Cross check the installation of pip software in the worker nodes, navigate to EC2 Dashboard and connect to EC2 Console of worker node and run the following command:

pip --version

Finally, we have successfully implemented the installation of python and Pip softwares on worker nodes from the Ansible manager node using ansible playbook.

Ansible – FAQ’s

What Is Ansible?

Ansible is open-source automating configuration management tool. In this we will define tasks defintion and configure the softwares in the worker nodes from the manager node.

How Does Ansible Differ From Other Automation Tools?

Ansible comes with agentless architecture. It features such as simplicity, and ease of use provides seamless configuration management across different environments.

What Are Ansible Playbooks?

Ansible playbook are files defined with YAML syntax. This files are defined with a set of tasks and definitions for executing the remote hosts providing automation of workflows.

Can Ansible Manage Both On-premises And Cloud-based Infrastructure?

Yes, Ansible capable of managing both on-premises and cloud based infrastructures with providing modules support.

How Does Ansible Ensure Security During Automation Tasks?

Ansible ensure security with providing features such as encrypted data storage, secure channel communication and with privileged escalation mechanisms during automation of tasks.


Article Tags :