Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DevOps Lifecycle
  • DevOps Roadmap
  • Docker Tutorial
  • Kubernetes Tutorials
  • Amazon Web Services [AWS] Tutorial
  • AZURE Tutorials
  • GCP Tutorials
  • Docker Cheat sheet
  • Kubernetes cheat sheet
  • AWS interview questions
  • Docker Interview Questions
  • Ansible Interview Questions
  • Jenkins Interview Questions
Open In App
Next Article:
How To Install Java Using Ansible PlayBook ?
Next article icon

How To Install PIP Using Ansible ?

Last Updated : 26 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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

  • Ansible: An open-source automating configuration management tool that is used for application deployment and task automation.
  • Playbook: It is a file with YAML syntax that used in defining a set of tasks and configurations that is executed by Ansible on remote hosts.
  • Inventory: It is a file that contains a list of hosts that are the worker nodes details that are used by Ansible manager for ensuring worker nodes that can be static or dynamically generated.
  • Module: A discrete unit of code in Ansible responsible for performing specific tasks on managed nodes, such as installing packages or copying files.
  • Task: A Task is a single unit of work defined within an Ansible playbook, representing an action to be executed on a remote host.
  • Worker Node: A node in a distributed computing environment responsible for executing tasks or workloads, often part of a cluster managed by tools like Kubernetes or Hadoop.

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.

  • Firstly lets create Ansible Manager Node. Provide the name of the instance as "Ansible Manger Node" , Number of Instances as "1" and choose the AMI as "Amazon Linux".

Creating-Instance

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.

Choosing-Created-Key-Pair

  • Configure the Security Groups with providing the all accesses such as Allowing traffic , protocols and ports, so that we don't face any security restrictions from the AWS Instance. The following screenshot illustrates it clearly.

Configure-Security-Groups

  • After Configuring the security groups checking the defined values once and click on launch instance as confirmation.

Step 3: Running Instances

  • After launching the instance, it takes some time to come for running state. Here we guided you to create Ansible Manager Node perform step 1 and step 2 again to create 2 worker nodes with name such as "Ansible Worker Node 1" and "Ansible Worker Node 2" with choosing same key pair file that choosen for Manager Node.
  • The following screenshot shows successful running of all these 3 Instances.

Running-Instances

Step 4: Connect Manager Node

  • Now, Connect to Ansible Manager Node by checking the instance and clicking on Connect button as shown in below screenshot.

Connect-Manager-Node

Step 5: Connect EC2 Console

  • After coming to the Ansible Manager Node instance go to the EC2 Instance Connect section and then click on Connect Button.

EC2-Console

Step 6: Install Ansible

  • On accessing the EC2 Console, now install the ansible software with the following command:
yum install ansible -y

Install-Ansible

Step 7: Verify Ansible

  • After installing the ansible software, verify it successfully installed or not with checking the ansible version by following command:
ansible --version

Verify-Ansible

Step 8: Copy Pem file

  • Now, Come to your laptop open the choosen/dowloaded pem key file and copy the key as shown in the below screenshot.

Copy-the-Private-Key

Step 9: Adding Permission To Pem File

  • Save the pem file to your instance as shown in the screenshot below with file name "myssh_key.pem"

Copying-Pem-file

  • Now, provide the only read permission to the user for making the pem file more secured with the following command:
chmod 400 myssh_key.pem

Step 10: Create Inventory

  • Create an inventory with hosts file name and specify the worker ip and credentials as shown in the below screenshot.

Inventory

Step 11: Ping The Worker Nodes

  • After creating the inventory file with hosts as filename, check the connecting with the worker nodes with the following command:
ansible -i hosts all -m ping
  • The following screenshot illustrates clearly that our worker nodes are successfully pinging.

1ping-1

  • To check the connectivity with ping on ignoring the warning use the following command with -o option as follows:
ansible -i hosts all -m -o ping

Ping-2

Step 12: Define Playbook

  • Now create a create playbook file such as naming with myplaybook.yml and define the following code in it.
---
- 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
  • The following illustrates the same with practical screenshot.

Ansible playbook

Step 13: Run The Playbook

  • Now, run the defined playbook with the following command:
ansible-playbook -i hosts myplaybook.yml 
  • The following screenshot illustrates running of the playbook.

Playbook-Run

  • On getting the output of the playbook run process as shown in the below screenshot indicates we successfully installed the pip software in the worker nodes.

Playbook-output

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
  • The following screenshot illustrates successful installation of pip software in the Ansible worker Node 1.

Node1-Verify

  • The following screenshot illustrates successful installation of pip software in the Ansible worker Node 2.

Node2-Verify

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


Next Article
How To Install Java Using Ansible PlayBook ?

K

kattagopi6174
Improve
Article Tags :
  • DevOps
  • Dev Scripter
  • Ansible
  • Dev Scripter 2024

Similar Reads

  • How to Install Git Using Ansible ?
    Git is a powerful and broadly utilized version control system that assumes a crucial role in current software development work processes, it gives developers a powerful structure for tracking changes in source code, planning cooperative work, and managing project chronicles proficiently. With its co
    6 min read
  • How To Install Python Using Ansible Playbook ?
    Automation is now absolutely necessary for the effective management of software deployment and infrastructure in IT landscape. Ansible emerges as a main automation tool, eminent for its effortlessness, simplicity, and flexibility. Software installation, configuration management, and application depl
    7 min read
  • How to Install Helm using Ansible Playbook?
    Managing various infrastructure and applications under different conditions in the present dynamic IT landscape can challenge. Automation tools like Ansible assist with smoothing out these undertakings by providing a basic yet amazing method to automate configuration management, application deployme
    8 min read
  • How To Install Java Using Ansible PlayBook ?
    In today's dynamic IT landscape, effective management and automation of software installations across various servers are pivotal for maintaining consistency, dependability, and versatility. Ansible, an open-source automation tool, has acquired huge popularity for its simplicity and flexibility in a
    7 min read
  • How To Install HTTPD Using Ansible Playbook ?
    Ansible is an open-source automation tool that improves IT orchestration, the design of the board, and application deployment. It works over SSH and requires no agent to be installed on a managed host. It is lightweight, efficient, and easy to set up, making it suitable for automating tasks on a var
    8 min read
  • How To Install MYSQL Using Ansible Playbook ?
    Introducing MySQL physically on different servers can be a tedious and mistake-inclined process. Be that as it may, with Ansible, an open-source mechanization apparatus, you can computerize the establishment and setup of MySQL across your framework effectively and proficiently. By allowing you to de
    6 min read
  • How To Install Docker Using Ansible Playbook ?
    Docker is a software platform that allows you to build, test and deploy applications that use OS-Level virtualization to deliver software in packages called "containers". Containers - Docker package software into standardized units called "Containers". Docker is a stand-alone tool. which means no ne
    7 min read
  • How To Install Tomcat Using Ansible Playbook?
    Automating software installation and configuration tasks is fundamental for efficient DevOps practices. Ansible, an open-source automation tool, works on this interaction by permitting you to characterize the framework as code and automate tasks across various servers. In this article, we will zero
    7 min read
  • 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 di
    7 min read
  • How to Install Apache in Ubuntu using Ansible?
    Apache HTTP Server, commonly referred to as Apache, is a robust and broadly used web server for open-source web server programming. It is exceptionally adaptable and extensible, and it is famous for hosting websites and web applications. Ansible, then again, is a strong automation device that improv
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences