This document outlines the steps to set up your development environment and run tests using molecule.
It is recommended to use a Python virtual environment (venv) to manage dependencies.
-
Create a virtual environment:
python3 -m venv venv
-
Activate the virtual environment:
- On Linux/macOS:
source venv/bin/activate - On Windows:
.\venv\Scripts\activate
- On Linux/macOS:
-
Install dependencies:
pip install -r requirements.txt
Molecule is used for testing Ansible roles. Before running molecule tests, ensure your Docker environment is correctly configured.
-
Check Docker Context (if applicable): If you are using Docker Desktop or have multiple Docker contexts, you might need to set the
DOCKER_HOSTenvironment variable.First, list your Docker contexts:
docker context ls
Example output:
NAME DESCRIPTION DOCKER ENDPOINT ERROR default Current DOCKER_HOST based configuration unix:///var/run/docker.sock desktop-linux * Docker Desktop unix:///home/lucasbeyeler/.docker/desktop/docker.sockIf
desktop-linux(or a similar context pointing to Docker Desktop) is not the active context, you need to export theDOCKER_HOSTvariable. -
Set
DOCKER_HOST(if necessary):export DOCKER_HOST=unix:///home/lucasbeyeler/.docker/desktop/docker.sockNote: Adjust the path to
docker.sockbased on yourdocker context lsoutput. -
Run Molecule tests: Navigate to the
molecule/defaultdirectory (or the specific scenario you want to test) and run themolecule testcommand.cd molecule/default molecule test
This command will perform the following steps:
destroy,create,prepare,converge,idempotence,lint, andverify.