#Introduction
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
end
# Application server 1.
config.vm.define "ubuntu" do |ubuntu|
ubuntu.vm.hostname = "devopsroles.com"
ubuntu.vm.box = "bento/ubuntu-21.04"
ubuntu.vm.network :private_network, ip: "192.168.3.7"
ubuntu.vm.network :forwarded_port, host: 4566, guest: 4566
ubuntu.vm.network :forwarded_port, host: 8055, guest: 8080
end
end
Start and login into VM
vagrant up
vagrant ssh
The output terminal is as below

Install Ansible by using virtualenv
RHEL/CentOS 7
sudo yum install python3-virtualenv
Ubuntu/Debian
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

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