How to install Ansible by using Virtualenv


In this tutorial, How to install Ansible by using Virtualenv. You can test and deploy multiple Ansible versions with Virtualenv.

My lab

  • Host OS: Windows 10
  • Vagrant Box: ubuntu
  • Install Ansible on Ubuntu

Vagrant create ubuntu

Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.vm.provider :virtualbox do |vb|
  vb.memory = 1500
  vb.cpus = 2
# Application server 1.
config.vm.define "ubuntu" do |ubuntu|
  ubuntu.vm.hostname = "" = "bento/ubuntu-21.04" :private_network, ip: "" :forwarded_port, host: 4566, guest: 4566 :forwarded_port, host: 8055, guest: 8080

Start and login into VM

vagrant up
vagrant ssh

The output terminal is as below

Install Ansible by using virtualenv


sudo yum install python3-virtualenv


sudo apt-get update
sudo apt-get install python3-virtualenv

Set up virtualenv and Install Ansible

You need to create a “virtual environment” to host your local copy of Ansible.

virtualenv ansible2.9

This command creates a directory called ansible2.9 in your current working directory.

You must activate it

source ansible2.9/bin/activate

You should see the prompt change to include the virtualenv name.

(ansible2.9) $

The output terminal is as below

Let’s install Ansible

pip3 install ansible==2.9

The output terminal is as below


You have to install Ansible by using Virtualenv. I hope will this your helpful. Thank you for reading the DevopsRoles page!

, ,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.