Installing Ansible Inside a virtual environment

A Python virtual environment, often abbreviated to “virtual”, is a tool to create isolated Python environments. It separates different projects, each in its own environment, allowing different versions of Python to be installed without conflicts.

This allows software packages to be installed in different environments while allowing them to rely on the same third-party modules. A virtual environment also makes it easier to create multiple separate Python distributions.

About Ansible

Ansible is an open-source automation platform that enables developers and system administrators to manage IT infrastructure. Ansible Tower is a commercial product that extends Ansible’s capabilities by adding features such as job scheduling, role-based access control, and reporting.

Install Virtualenv

To create a virtual environment with Python we first need to install virtualenv which helps us create and manage virtual environments. We install it using the following command.

pip3 install virtualenv

Once virtualenv is installed it is recommended to place all virtual environments in a directory. for this post, I will create a directory called venv

mkdir venv

Create a Virtual Environment

To create a virtual environment for Ansible, I will use the following command. The environment name is ansible and I will run the command from the venv directory.

python3 -m virtualenv ansible

Activate and Install Ansbile

To activate the virtual environment I will run the following command. Inside each environment, there is a script called activate which active the environment.

source ansible/bin/activate

The last step and command below will install Ansible inside the virtual environment.

python -m pip install ansible

To exit (deactivate) the virtual environment, I will run the following command.


Leave a comment

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.