You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-4Lines changed: 65 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,35 @@ It provides tooling to create Molecule testing scenarios via the `init` role, an
8
8
9
9
When utilizing an image with systemd support (systemd packages are installed, etc.), the `docker_platform` role supports the creation of Docker containers with a functional Systemd implementation, which can be used to test Ansible code that makes use of Systemd services or related functionality.
10
10
11
+
# What is Molecule?
12
+
13
+
> Molecule project is designed to aid in the development and testing of Ansible roles.
14
+
15
+
Molecule is a testing platform for your Ansible projects that enables testing of your code both during development and after release via CI infrastructure.
16
+
17
+
Some resources on Molecule can be found here:
18
+
*[Developing and Testing Ansible Roles with Molecule and Podman - Part 1](https://www.ansible.com/blog/developing-and-testing-ansible-roles-with-molecule-and-podman-part-1)
19
+
*[Testing your Ansible roles with Molecule](https://www.jeffgeerling.com/blog/2018/testing-your-ansible-roles-molecule)
20
+
*[Ansible Collections: Role Tests with Molecule](https://ericsysmin.com/2020/04/30/ansible-collections-role-tests-with-molecule/)
21
+
*[Introducing Ansible Molecule with Ansible Automation Platform](https://developers.redhat.com/articles/2023/09/13/introducing-ansible-molecule-ansible-automation-platform#an_automation_testing_framework_built_for_the_enterprise)
22
+
23
+
> [!WARNING]
24
+
> Some [fairly significant changes](https://ansible.readthedocs.io/projects/molecule/next/) have been made in Molecule v6. Most noticable among these are likely to be that `ansible` is now the only driver included by default (previously called `delegated`), and that the `molecule init` command now only supports creation of scenarios, not Ansible roles.
25
+
>
26
+
> This [RedHat article](https://developers.redhat.com/articles/2023/09/13/introducing-ansible-molecule-ansible-automation-platform#) has some more information on this change.
27
+
>
28
+
> When reading the above referenced articles, keep in mind their publishing dates, and that there may have been breaking changes to Molecule's functionality since that time!
29
+
11
30
# Using this collection
12
31
32
+
The following roles are provided:
33
+
34
+
*[init](roles/init) - Initialize the Molecule testing framework for a project
35
+
*[docker_platform](roles/docker_platform) - Create a docker-based test platform for Molecule
36
+
*[prepare_controller](roles/prepare_controller) - Prepare a molecule controller to run local code tests
37
+
38
+
The recommended way to use this collection is to provision Molecule scenarios using the [init role](roles/init). The `init` role provides template configurations that will work in various project types.
39
+
13
40
## Host Requirements
14
41
15
42
The host from which this collection is run (workstation, CI instance, etc.) must meet the following requirements:
@@ -35,7 +62,7 @@ Docker CE can be installed by following the appropriate [installation instructio
35
62
36
63
## Project requirements
37
64
38
-
Roles within this collection will attempt to discover what type of project they are being utilized in. This is enabled by setting the appropriate `project_type` configuration variable to `auto`. The project type can also be explicitly specified if this is desired.
65
+
The `init` role from this collection will attempt to discover what type of project it is being utilized in. This is enabled by setting the `init_project_type` configuration variable to `auto`. The project type can also be explicitly specified if this is desired.
39
66
40
67
Supported project types:
41
68
*`role`
@@ -146,17 +173,51 @@ or if your `collections/requirements.yml` includes this collection:
#### Testing roles and playbooks within a monolithic project
177
+
178
+
When configuring molecule testing for individual roles or playbooks within a monolithic project (creating a `roles/<role_name>/molecule` or `playbooks/<playbook_name>/molecule` directory), take care _not_ to name the scenario "default", as there is already a "default" scenario for the monolithic project itself if you have created `molecule/default` as described above! Instead, name your role scenario with a unique name.
150
179
151
-
When configuring molecule testing for individual roles within a monolithic project (creating a `roles/<role_name>/molecule` directory), take care _not_ to name the scenario "default", as there is already a "default" scenario for the monolithic project itself if you have created `molecule/default` as described above! Instead, name your role scenario with a unique name.
Note that in this circumstance, you will need to specify the scenario name in order to run molecule against it (as it is not named `default`).
190
+
191
+
> [!WARNING]
192
+
> Creating more than one `default` scenario within a repository (IE: within individual roles) will cause Molecule to fail to run at the outer project level!
193
+
194
+
Running the `molecule list` command will provide you an overview of the available scenarios
195
+
196
+
```bash
197
+
❯ molecule list
198
+
INFO Running pb-example_playbook > list
199
+
╷ ╷ ╷ ╷ ╷
200
+
Instance Name │ Driver Name │ Provisioner Name │ Scenario Name │ Created │ Converged
And running the full test suite for this playbook would be done as:
207
+
208
+
```bash
209
+
molecule test -s pb-example_playbook
210
+
```
211
+
212
+
While running just the "converge" steps (IE: during development) would be:
213
+
214
+
```bash
215
+
molecule converge -s pb-example_playbook
216
+
```
217
+
218
+
> [!TIP]
219
+
> The `molecule list` command will show multiple scenarios when run in the root of a monolithic project that also has molecule configured on individual playbooks or roles contained within it. Note that you will, however, still need to be in the appropriate role or playbook directory in order to successfully run these scenarios!
0 commit comments