First Molecule is a tool in the Ansible box used to enable automatic role testing and SourceHut is a software forge, an alternative to Github that I appreciate.
In the official documentation section § CI/CD Usage there is no mention of SourceHut so I decided to write one of my own.
Here is an example of build manifest for the role ansible-role-whatever
on Debian buster:
image: debian/buster
packages:
- python3
- python3-pip
- python3-wheel
- python3-setuptools
sources:
- https://git.sr.ht/~somebody/ansible-role-whatever
environment:
PATH: "/bin:/usr/bin/:/usr/local/bin:/home/build/.local/bin"
tasks:
- pip: |
python3 -m pip install -qU pip
python3 -m pip install -q ansible
python3 -m pip install -q molecule
- molecule: |
cd ansible-role-whatever
molecule test -s debian-buster
Feel free to pin specific versions of both ansible and molecule to suit your needs.
Molecule is essentially designed to run tests inside a Docker container but provides other options named “drivers”, such as Vagrant, Podman, Hetzner Cloud VPS or even Google Cloud Engine. What they all do is to spin one or more instances, deploy some code on it and test the role. To run on SourceHut the other way around is actually needed: a VM is created already containing the code and molecule should run inside it. This behaviour is available with the “delegated” driver.
Here is an example of a molecule.yml
configuration file:
---
dependency:
name: galaxy
enabled: no
driver:
name: delegated
options:
managed: no
ansible_connection_options:
ansible_connection: local
platforms:
- name: instance
provisioner:
name: ansible
verifier:
name: ansible
I personally like to tidy up the scenario
part to the minimum but this is perfectly optional:
scenario:
check_sequence:
- converge
- check
converge_sequence:
- converge
test_sequence:
- converge
- idempotence