[Proposal] Add ansible molecule to test roles#875
Open
AntoineDupre wants to merge 5 commits intoseapath:mainfrom
Open
[Proposal] Add ansible molecule to test roles#875AntoineDupre wants to merge 5 commits intoseapath:mainfrom
AntoineDupre wants to merge 5 commits intoseapath:mainfrom
Conversation
1842e5d to
aac490d
Compare
aac490d to
c68bc90
Compare
dupremathieu
approved these changes
Mar 5, 2026
c68bc90 to
ec17fe1
Compare
Signed-off-by: Antoine Dupre <antoine.dupre@savoirfairelinux.com>
Signed-off-by: Antoine Dupre <antoine.dupre@savoirfairelinux.com>
Signed-off-by: Antoine Dupre <antoine.dupre@savoirfairelinux.com>
Signed-off-by: Antoine Dupre <antoine.dupre@savoirfairelinux.com>
Signed-off-by: Antoine Dupre <antoine.dupre@savoirfairelinux.com>
ec17fe1 to
2fdad0d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here a proposal to add ansible molecule in seapth ansible.
This PR introduces Molecule into the repository in order to add unit testing for Ansible roles.
Why molecule
Currently, roles are tested through full playbook execution as part of the global deployment workflow.
While this validates integration at the playbook level, it does not provide:
Molecule addresses these limitations by allowing each role to be tested independently from the full Seapath deployment environment. It brings:
molecule testinside a role)How Molecule works
Molecule orchestrates a full test around an Ansible role.
A role test is organized into scenarios, located under:
Each scenario contains a
molecule.ymlfile describing the test configuration.A scenario typically includes:
testinfra.For each scenario, Molecule runs test sequence like:
By default, Molecule runs the role twice to validate idempotency (i.e., the second run should not report changes).
It is important to note that Molecule does not introduce new testing logic that could not be achieved with Ansible alone.
It provides a structured and standardized framework around Ansible to:
What this PR introduces
This PR provides an initial implementation of Molecule tests for the
network_basicrole.It demonstrates:
Two scenarios are provided:
1.
defaultscenarioTests the standard behavior of the role.
It includes:
molecule.yml: Defines the test environment configuration.converge.yml: A playbook that applies the network_basic role with default variables.prepare.yml: Sets up the test environment before the role execution.verify.yml: Verifies that the expected network configuration is present using Ansible assertions.This scenario validates the normal usage of the role.
2.
wipescenarioTests the behavior of the role when using the variables that wipe network directories before deployment.
This scenario specifically validates that:
idempotency disabled for this scenario
By default, Molecule runs an idempotency test, meaning it executes the role twice to ensure that the second run produces no changes.
However, in this case, the role:
This workflow is intentionally destructive and cannot be strictly idempotent in the classical sense.
For this reason, the idempotency step has been disabled for this scenario.
Addition of Tox for test orchestration
This PR also introduces tox at the repository root. It brings:
Molecule test can be directly run from each role directory:
It requires some orchestration to be run from the seapath-ansible root directory. Tox provides this orchestration.
Tests can now be executed from the repository root with:
This command:
-Discovers roles that contain a molecule/ directory
molecule test --allfor each of themConclusion
The goal of introducing Molecule in this repository is to progressively generalize the practice of adding unit tests for Ansible roles, especially for the development of future roles.
This initial implementation should be seen as a foundation rather than a final state. Over time, we aim to:
Introducing systematic role testing will also help highlight roles that are not strictly idempotent.
In some cases, this may encourage restructuring them to better align with Ansible’s philosophy: describing a desired state rather than executing a sequence of imperative actions.
This PR is a first step toward a more test-driven and quality-oriented approach to role development within the project.