Parallel tests

Molecule does not randomize the instance name

It’s of course possible to launch multiple tests in parallel but if you use the same instance name in all your molecule.yml file, they will collide and fail.

To avoid this potential problem, it’s possible a find a unique name by using the environment variable expansion feature.

Update molecule.yml

In the platform block, where the instance name is defined, just include a variable:

  - name: 'target-debian-${MOLECULE_INSTANCE_NAME_ID:-1}'

On your computer

Before a run, just export the MOLECULE_INSTANCE_NAME_ID variable with a random content.

On a CI/CD platform

It’s the same mechanism: just export the MOLECULE_INSTANCE_NAME_ID.

For GitHub Actions, use the github.run_id variable:

- name: Test with molecule
    MOLECULE_INSTANCE_NAME_ID: '${{ github.run_id }}'
  run: |
        molecule test -s docker_${{ matrix.distribution }}

For Gitlab CI, use the CI_JOB_ID variable: