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
The `init` role now supports playbooks - use by following the `mkdir -p molecule/pb-<playbook_name>` etc. commands in the role README.
The `init` role now supports monolithic repositories - IE creating your `molecule` folder in the root of the monolith repo
The `docker_platform` role now supports adding Ansible inventory vars to the created test hosts
Add more complete tests for this role itself, specifically tests for the `init` role.
Copy file name to clipboardExpand all lines: README.md
+79-5Lines changed: 79 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,22 @@ 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.
-[Testing roles and playbooks within a monolithic project](#testing-roles-and-playbooks-within-a-monolithic-project)
22
+
-[Playbooks](#playbooks)
23
+
-[Using Molecule](#using-molecule)
24
+
-[Ansible Tags](#ansible-tags)
25
+
-[Contributing](#contributing)
26
+
11
27
# What is Molecule?
12
28
13
29
> Molecule project is designed to aid in the development and testing of Ansible roles.
@@ -27,6 +43,8 @@ Some resources on Molecule can be found here:
27
43
>
28
44
> 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
45
46
+
More tips on using Molecule can be found [below](#using-molecule).
47
+
30
48
# Using this collection
31
49
32
50
The following roles are provided:
@@ -65,9 +83,10 @@ Docker CE can be installed by following the appropriate [installation instructio
65
83
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.
66
84
67
85
Supported project types:
68
-
*`role`
69
86
*`collection`
70
87
*`monolith`
88
+
*`playbook`
89
+
*`role`
71
90
72
91
When used with a role or collection, the Galaxy meta information for the role must be configured!
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
209
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
210
Running the `molecule list` command will provide you an overview of the available scenarios
195
211
196
212
```bash
@@ -203,6 +219,7 @@ INFO Running pb-example_playbook > list
203
219
╵ ╵ ╵ ╵ ╵
204
220
```
205
221
222
+
206
223
And running the full test suite for this playbook would be done as:
> 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!
236
+
> 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!
237
+
238
+
### Playbooks
239
+
240
+
Playbook configurations are similar to the `monolith` project type noted above, and are typically contained within monolithic projects. A project directory is considered a playbook if it contains a `tasks/` folder, but no role `meta/main.yml` configuration, and no `playbooks/` subdirectory.
241
+
242
+
A playbook project configuration may look like:
243
+
244
+
```
245
+
playbooks
246
+
├── your_playbook
247
+
│ ├── main.yml
248
+
│ ├── README.md
249
+
│ ├── tasks
250
+
│ │ ├── asserts.yml
251
+
│ │ ├── main.yml
252
+
│ │ └── standard.yml
253
+
│ └── vars
254
+
└── [...]
255
+
```
256
+
257
+
Playbook configuration adds the following directories to the role path configuration (paths relative to the playbook `main.yml` or equivilant file):
258
+
259
+
* `./roles`
260
+
* `./../roles`
261
+
* `./../../roles`
262
+
263
+
It also adds the following directories to the collection path configuration (paths relative to the playbook `main.yml` or equivilant file):
264
+
* `./collections`
265
+
* `./../collections`
266
+
* `./../../collections`
267
+
268
+
# Using Molecule
269
+
270
+
The most common Molecule commands that you will likely use are:
271
+
272
+
```bash
273
+
molecule create # Create the test infrastructure, as defined in molecule.yml
274
+
molecule converge # Run the plays from converge.yml (launch your role/playbook)
275
+
molecule verify # Run the plays from verify.yml (test for desired state)
276
+
molecule test # Run the full test sequence
277
+
```
278
+
279
+
## Ansible Tags
280
+
281
+
If [tags](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_tags.html) are used in your code to enable/disable certian functionality, they must be specified on the command line when running Molecule commands. To do so, use the `--` [command line option](https://ansible.readthedocs.io/projects/molecule/usage/#test-sequence-commands) to pass commands through to `ansible-playbook`.
282
+
283
+
For example:
284
+
285
+
```bash
286
+
molecule test -- --tags the-cheese
287
+
```
288
+
289
+
Or running `converge` using a non-default scenario:
0 commit comments