Using “pip” is the supported installation method for Ansible and Molecule. Let’s install Python libraries and applications (in this case, Ansible and Molecule) in a Python virtual environment. (This post is similar to the one about Ubuntu.)
First, install the required packages, including the Python virtual environment package:
1 |
sudo pacman -S python-pip python-virtualenv |
Create a virtual environment somewhere (in this example, I create it in my home folder as a subdirectory of a folder for all the virtual environments; the directory will be created automatically):
1 |
python -m venv ~/.venv/molecule |
Once the virtual environment has been created, “enter” the virtual environment:
1 |
source ~/.venv/molecule/bin/activate |
Install the Python packages for Ansible, Molecule, and its plugins in the virtual environment:
1 |
python -m pip install ansible molecule "molecule-plugins[docker]" yamllint ansible-lint |
You can verify that everything is installed correctly, e.g., at the time of writing:
1 2 3 4 5 6 7 8 9 10 11 12 |
❯ molecule --version molecule 25.4.0 using python 3.13 ansible:2.18.5 gce:23.7.0 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0 openstack:23.7.0 from molecule_plugins requiring collections: openstack.cloud>=2.1.0 containers:23.7.0 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1 docker:23.7.0 from molecule_plugins requiring collections: community.docker>=3.10.2 ansible.posix>=1.4.0 default:25.4.0 from molecule azure:23.7.0 from molecule_plugins ec2:23.7.0 from molecule_plugins vagrant:23.7.0 from molecule_plugins podman:23.7.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0 |
Each time you want to run Ansible or Molecule, just run the “source” command above:
1 |
source ~/.venv/molecule/bin/activate |
And then you can run “ansible” and “molecule”.
When using “Oh My Zsh” with the “Powerlevel10k” theme, you also get the virtual environment name shown in the prompt: