How to install Ansible by using Virtualenv

#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

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

install Ansible by using Virtualenv

Let’s install Ansible

pip3 install ansible==2.9

The output terminal is as below

install Ansible by using Virtualenv

Conclusion

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 DevopsRoles.com 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 *

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