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.
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.
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
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.
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.