HUB
Sign inSign up
ansible-molecule logo

jfxs/ansible-molecule

By jfxs

•Updated 5 days ago

The jfxs/ansible image with Molecule and its `docker` driver to run the Molecule tests in CI

Image
0

193

jfxs/ansible-molecule repository overview

⁠Docker ansible-molecule

Software License Pipeline Status

The jfxs/ansible⁠ image with Molecule⁠ and its docker driver, to run the Molecule tests of Ansible roles in a CI without installing the Python libraries at each job.

  • everything of the jfxs/ansible⁠ image (ansible-core, ansible-lint, testinfra, yamllint, go-task...),
  • molecule, molecule-plugins[docker] and the Docker Python SDK (docker). No Docker CLI: use the community.docker.docker_api connection in molecule.yml, which only needs the SDK and DOCKER_HOST,
  • non-root container user and arbitrary UID support, as in the base image,
  • multiarch with support of amd64 and arm64,
  • automatically kept up to date by Renovate⁠ (base image, Molecule and its Python dependencies),
  • automatically rebuilt every week,
  • image signed with Cosign⁠, with a software bill of materials (SBOM) attestation,
  • available on Docker Hub and Quay.io.

GitLab The main repository.

Docker Hub The Docker Hub registry.

Quay.io The Quay.io registry.

The collections (community.docker, ansible.posix...) are not in the image, as in jfxs/ansible: the dependency step of Molecule installs them. The platform images, with systemd, are jfxs/molecule-ubuntu⁠ and jfxs/molecule-debian⁠.

⁠Usage in a GitLab CI

molecule:
  image: jfxs/ansible-molecule
  services:
    - docker:dind
  variables:
    DOCKER_HOST: "tcp://docker:2375"
    DOCKER_TLS_CERTDIR: ""
  script:
    - molecule test

With the docker driver, the molecule.yml platforms need privileged: true, cgroupns_mode: host and the /sys/fs/cgroup volume (see the platform images). The connection of the instances:

provisioner:
  name: ansible
  inventory:
    host_vars:
      instance:
        ansible_connection: community.docker.docker_api
        # The docker_api connection does not read DOCKER_HOST from the environment.
        ansible_docker_docker_host: "{{ lookup('ansible.builtin.env', 'DOCKER_HOST') | default('unix:///var/run/docker.sock', true) }}"

Locally, with the socket of your Docker daemon (-u 0 is only needed to access the socket, the image runs as non-root otherwise):

docker run -it --rm -u 0 -v /var/run/docker.sock:/var/run/docker.sock -v "$(pwd)":/ansible jfxs/ansible-molecule molecule test

⁠Build and test locally

task install-templates          # fetch the task templates (first time)
task 00:010-build-local         # build ansible-molecule
task 00:020-test-local          # tests/acceptance.sh

Without task: docker build -t ansible-molecule . then tests/acceptance.sh ansible-molecule.

tests/acceptance.sh checks that molecule, the Docker SDK and the Molecule plugins work, that the image runs as non-root and with an arbitrary UID, and runs a complete Molecule scenario (tests/molecule/default: create, converge, idempotence, verify, destroy) on a jfxs/molecule-debian platform. It needs a Docker daemon that accepts privileged containers and the host cgroup namespace.

⁠Dependencies and Renovate

  • Dockerfile: the base image (IMAGE_ANSIBLE, tag of the jfxs/ansible minor version and digest) and ARG VERSION, the Molecule version.
  • requirements.txt: the other Python packages added to the base image (molecule-plugins, docker and their dependencies, pip freeze format).

Renovate⁠ bumps them all, the Python ones in a single merge request. The build keeps the packages of the base image as they are (pip constraints): if a new Molecule needs another version of one of them, the build fails until the base image is updated.

To regenerate requirements.txt after adding a package, in the base image:

docker run --rm -u 0 --entrypoint sh jfxs/ansible -c 'pip freeze --exclude-editable > /tmp/base.txt && pip install -q -c /tmp/base.txt molecule=="<version>" "molecule-plugins[docker]" && pip freeze | grep -vxFf /tmp/base.txt'

(remove molecule from the result: its version is the ARG VERSION of the Dockerfile).

⁠Built with

Docker latest tag is 26.10.0-001, 26.10, 26⁠.

Dockerhub Overview page⁠ has the details of the last published image.

⁠Versioning

Docker tag definition:

  • the molecule version used,
  • a dash
  • an increment to differentiate build with the same version starting at 001
<molecule_version>-<increment>

Example: 26.10.0-001

⁠Signature and attestation

The image is signed with Cosign⁠ and carries a SBOM attestation:

cosign verify --key cosign.pub $IMAGE_URI
cosign verify-attestation --key cosign.pub --type spdxjson $IMAGE_URI | jq '.payload | @base64d | fromjson | .predicate'

The public key is available online: https://gitlab.com/op_so/docker/cosign-public-key/-/raw/main/cosign.pub⁠.

⁠Authors

⁠License

This program is free software: you can redistribute it and/or modify it under the terms of the MIT License (MIT). See the LICENSE⁠ for details.

Tag summary
Recent tags
Content type
Image
Digest
sha256:322db2fd0…
Size
87.3 MB
Last updated
5 days ago
docker pull jfxs/ansible-molecule:latest