0Pricing
Ansible Academy · Lesson

molecule init & the Scenario Layout

Scaffold a test harness for a role.

molecule init & the Scenario Layout is a free Ansible Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ansible Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Scaffold a Test Harness

The molecule init command generates a ready-to-run test setup so you do not write boilerplate by hand.

Init Inside a Role

Run init from your role's root to add a scenario without touching your existing tasks or handlers.

molecule init scenario

What Is a Scenario?

A scenario is one complete test configuration: which host to create, how to run the role, and how to verify it.

The default Scenario

Init creates a folder named default under molecule/. It is the scenario that runs when you do not name another.

molecule/
  default/

molecule.yml: The Brain

The molecule.yml file wires together the driver, platforms, provisioner, and verifier for this scenario.

molecule/default/molecule.yml

Pick a Driver & Platform

The platforms block lists test hosts. With the Docker driver you just name a base image to spin up.

platforms:
  - name: instance
    image: ubuntu:22.04

converge.yml Applies Your Role

The converge.yml playbook is what actually runs your role against the test host during a test.

- hosts: all
  roles:
    - role: my_role

verify.yml Checks the Result

A verify.yml playbook holds your assertions: it confirms the role left the host in the state you expect.

molecule/default/verify.yml

Multiple Scenarios

You can add more named scenarios beside default, for example to test the same role on a second OS image.

molecule init scenario centos

Target One Scenario

Use the -s flag to run a specific scenario by name instead of the default one.

molecule test -s centos

Commit the Scenario

The whole molecule/ folder is plain text. Commit it to Git so every teammate runs the exact same test setup.

Quick Check

Recall which file configures a Molecule scenario.

Recap

molecule init scenario scaffolds a default scenario: molecule.yml configures it, converge.yml applies the role, verify.yml asserts the result. 🗂️

Frequently asked questions

Is the “molecule init & the Scenario Layout” lesson free?

Yes — the full text of “molecule init & the Scenario Layout” is free to read here on the web, and the Ansible Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ansible Academy course, upgrade to CoddyKit PRO.

What will I learn in “molecule init & the Scenario Layout”?

Scaffold a test harness for a role. You practise Ansible Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Ansible Academy?

No prior experience is required. Ansible Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “molecule init & the Scenario Layout” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Ansible Academy lesson?

Yes. Every Ansible Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Why Test Infrastructure Code
  2. molecule init & the Scenario Layout
  3. Converge, Verify & the Test Matrix
  4. Idempotence & Lint in the Pipeline
← Back to Ansible Academy