FEAT: Local test harness using Molecule and Kind for Ansible role development and CI #63

Open
opened 2026-05-16 20:05:58 +00:00 by mconway · 0 comments
Owner

Summary

There is currently no automated testing framework for Ansible roles in this repo. A local test harness should be created using Molecule and Kind (Kubernetes-in-Docker) so that roles can be validated during development and in CI/CD pipelines, with the environment torn down after each run.

Goals

  • Validate Ansible roles in an ephemeral environment before merging
  • Support both local developer runs and automated pipeline execution
  • Full teardown after tests complete (pass or fail)
  • Cover both Linux host roles and Kubernetes (k8s-*) roles

Proposed setup

Molecule

  • Add a molecule/ directory to roles that need testing
  • Use the molecule-plugins[docker] driver for Linux host roles
  • Use the molecule-plugins[delegated] driver targeting a Kind cluster for k8s-* roles
  • Default scenario: create → converge → verify → destroy

Kind

  • Spin up a Kind cluster as part of the Molecule create phase for Kubernetes roles
  • Install prerequisites into the cluster (cert-manager, ingress-nginx, etc.) as needed per role
  • Destroy the Kind cluster in the destroy phase regardless of test outcome

Verification

  • Use ansible.builtin.assert tasks or dedicated Molecule verifier steps to check role outcomes
  • For k8s roles: verify Helm releases are deployed, pods are running, ingress resources exist

Pipeline integration

  • Add a CI pipeline definition (Forgejo Actions / .forgejo/workflows/) that:
    • Installs dependencies (Molecule, Kind, Helm, kubectl)
    • Runs molecule test for each role with a molecule scenario
    • Always tears down the Kind cluster on completion

Acceptance criteria

  • At least one Linux host role and one k8s-* role have a working Molecule scenario
  • molecule test runs end-to-end locally without manual cleanup
  • Kind cluster is always destroyed after tests, even on failure
  • A Forgejo Actions workflow runs the test harness on pull requests
  • README or CONTRIBUTING doc describes how to run tests locally
## Summary There is currently no automated testing framework for Ansible roles in this repo. A local test harness should be created using [Molecule](https://ansible.readthedocs.io/projects/molecule/) and [Kind](https://kind.sigs.k8s.io/) (Kubernetes-in-Docker) so that roles can be validated during development and in CI/CD pipelines, with the environment torn down after each run. ## Goals - Validate Ansible roles in an ephemeral environment before merging - Support both local developer runs and automated pipeline execution - Full teardown after tests complete (pass or fail) - Cover both Linux host roles and Kubernetes (k8s-*) roles ## Proposed setup ### Molecule - Add a `molecule/` directory to roles that need testing - Use the `molecule-plugins[docker]` driver for Linux host roles - Use the `molecule-plugins[delegated]` driver targeting a Kind cluster for `k8s-*` roles - Default scenario: `create → converge → verify → destroy` ### Kind - Spin up a Kind cluster as part of the Molecule `create` phase for Kubernetes roles - Install prerequisites into the cluster (cert-manager, ingress-nginx, etc.) as needed per role - Destroy the Kind cluster in the `destroy` phase regardless of test outcome ### Verification - Use `ansible.builtin.assert` tasks or dedicated Molecule verifier steps to check role outcomes - For k8s roles: verify Helm releases are deployed, pods are running, ingress resources exist ## Pipeline integration - Add a CI pipeline definition (Forgejo Actions / `.forgejo/workflows/`) that: - Installs dependencies (Molecule, Kind, Helm, kubectl) - Runs `molecule test` for each role with a molecule scenario - Always tears down the Kind cluster on completion ## Acceptance criteria - [ ] At least one Linux host role and one `k8s-*` role have a working Molecule scenario - [ ] `molecule test` runs end-to-end locally without manual cleanup - [ ] Kind cluster is always destroyed after tests, even on failure - [ ] A Forgejo Actions workflow runs the test harness on pull requests - [ ] README or CONTRIBUTING doc describes how to run tests locally
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mconway/Homelab#63
No description provided.