Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

The reliable way to test an Ansible role on an Ubuntu development machine is to use Molecule with a disposable target managed by a supported driver such as Podman. Install Ansible, Molecule, and the driver required by your project; initialize a scenario inside the role repository; apply the role in converge.yml; assert the resulting state in verify.yml; then run molecule test. Molecule performs dependency installation, cleanup, instance creation, convergence, idempotence testing, verification, and final destruction in a repeatable sequence.

Ubuntu is the host operating system in this guide. The system being tested can be an Ubuntu container, virtual machine, cloud instance, API, database, network device, or another target reachable by Ansible. Choose the target and driver according to the role’s support policy rather than assuming that an Ubuntu host requires an Ubuntu target.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What Molecule tests

Molecule is an Ansible testing framework for developing and testing collections, playbooks, and roles. It supplies a scenario structure, a driver interface for creating test systems, and commands for applying and checking a role. A scenario can use containers, virtual machines, cloud infrastructure, APIs, databases, network devices, or any other system that Ansible can reach.

A normal role test answers several different questions:

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.
  • Can the role be applied to a clean target?
  • Does a second application make no unintended changes (idempotence)?
  • Did the target reach the required state?
  • Are resources cleaned up even after a failure?

The complete default lifecycle is dependency, destroy, create, converge, idempotence, verify, and a final destroy. The scenario can change that order, but changing it should be a deliberate testing decision.

Prerequisites on Ubuntu

Install the tools using your project policy

The official role tutorial treats Ansible, Molecule, and Podman as prerequisites. On Ubuntu, select an installation method that matches the Python and Ansible policy used by your repository. Depending on the project, that may be a distribution package, a virtual environment, or an isolated command-line installation. The important requirement is not a particular package command; it is that the versions installed on your machine are compatible with the role, Molecule, and the selected driver.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not copy a package command or version pin from an unrelated project and assume it is universal. Ubuntu package availability, Python versions, Ansible compatibility windows, Molecule releases, and driver collections change. After installation, confirm that the executables you intend to use are on your PATH:

  • ansible --version
  • molecule --version
  • podman --version when Podman is your driver

Also confirm that your user can run the selected driver, create its resources, and access any registry or cloud credentials required by the scenario. A role that only manages files and services may need no cloud credentials, while a scenario targeting external infrastructure may require authentication and network access.

Keep host and target requirements separate

Your Ubuntu workstation needs the Molecule command and its Python dependencies. The target needs whatever the role manages: a package manager, a service manager, Python support for Ansible modules, or other prerequisites. If the target is a minimal container, the image may not contain all of those components. Put bootstrap work in the scenario’s creation or preparation steps, or select an image that already satisfies the role’s documented prerequisites.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Recommended role repository layout

Work from the root of the role, not from the parent directory that contains several roles. A conventional repository looks like this:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
my_role/
├── tasks/
│   └── main.yml
└── molecule/
    └── default/
        ├── molecule.yml
        ├── requirements.yml
        ├── inventory/
        │   └── hosts.yml
        ├── create.yml
        ├── converge.yml
        ├── verify.yml
        └── destroy.yml

The role’s implementation remains under directories such as tasks/, handlers/, templates/, and defaults/. The molecule/ directory contains tests and is separate from those task files. Each scenario is a self-contained directory. default is merely the conventional first scenario name; you can add directories such as ubuntu, upgrade, or cloud when the role needs different inputs or platforms.

Initialize the default scenario

  1. Change to the role directory: cd my_role.
  2. Initialize the conventional scenario: molecule init scenario default.
  3. Inspect the generated files and commit them with the role when the scenario is ready for collaboration.

The generated files are a starting point, not a complete test. Review the driver, platform definition, inventory, lifecycle sequence, and role path before the first run. Keep the scenario’s role lookup unambiguous: the project configuration should make the role under test discoverable without relying on a developer’s current directory or a globally installed copy.

Declare driver collections

If the driver is distributed as an Ansible collection, declare it in molecule/default/requirements.yml. The official example uses the containers.podman collection. A requirements file can contain the collection declaration required by your chosen driver; do not add unrelated collections simply because they are available. Run the scenario’s dependency phase after changing this file so the declared collection is installed in the environment used by Molecule.

Configure the scenario

molecule.yml controls the driver, platforms, inventory, and action sequence. At minimum, make sure it identifies the selected driver, defines the target platform or platforms, points Ansible at the scenario inventory, and includes the actions you want to run. A minimal structural example is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
dependency:
  name: galaxy

driver:
  name: podman

platforms:
  - name: instance
    groups:
      - molecule

provisioner:
  name: ansible
  inventory:
    hosts: inventory/hosts.yml

scenario:
  test_sequence:
    - dependency
    - destroy
    - create
    - converge
    - idempotence
    - verify
    - destroy

The exact platform fields are driver-specific. Add the image, connection, privilege, and other settings required by the driver and approved by your project. There is no single Ubuntu image tag or universal combination that is correct for every role. Keep the molecule host group consistent with the plays in your converge and verify files.

Apply the role in converge.yml

converge.yml is the playbook that applies the role under test. Target the scenario’s molecule group and include the role explicitly. The role guide’s pattern is:

---
- name: Converge
  hosts: molecule
  gather_facts: false
  tasks:
    - name: Apply the role under test
      ansible.builtin.include_role:
        name: my_role

Replace my_role with the role name as Ansible resolves it in your repository. Set gather_facts to true when the role needs facts; leaving it false makes a test faster and exposes roles that accidentally depend on facts they never requested. Pass representative variables in the play or through scenario variables, and include separate plays when the role must be exercised under more than one input set.

Keep convergence focused on setup and application. Assertions belong in verify.yml, where a failure clearly means that the resulting state is wrong rather than that the role could not be applied.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Assert the end state in verify.yml

A verification playbook inspects the target after convergence and fails with a useful message when the expected state is absent. For a role that creates a marker file, an Ansible-native check can be written as:

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
---
- name: Verify
  hosts: molecule
  gather_facts: false
  tasks:
    - name: Read the role marker file
      ansible.builtin.stat:
        path: /tmp/molecule_role_marker
      register: marker

    - name: Confirm the role created the marker file
      ansible.builtin.assert:
        that:
          - marker.stat.exists
          - marker.stat.isreg

Use checks that represent the contract of the role, not its implementation details. Examples include a service being enabled and running, a configuration file containing the required setting, a user having the intended attributes, a package being present at an acceptable version, or a file having the expected owner and mode. Register a module result once and assert several properties from it when that makes failures easier to interpret.

Assertions should be deterministic and safe to run repeatedly. Avoid checks that depend on wall-clock time, random identifiers, an administrator’s personal environment, or an external service unless those dependencies are the subject of the scenario.

Run the lifecycle

Command Use it for What it does not guarantee
molecule test End-to-end validation It cannot compensate for an incorrect scenario or weak assertions.
molecule converge Fast development iterations It does not run verification or necessarily destroy the instance.
molecule verify Re-running assertions against an existing instance It does not create a missing instance.
molecule create Creating the test target for inspection It does not apply the role.
molecule list Seeing scenario instances and their state It does not diagnose the cause of a failed task.
molecule login Opening an interactive session in the instance It is unavailable if creation failed or the instance was destroyed.
molecule destroy Removing instances and stale resources It does not preserve evidence unless you collect it first.

During normal development, use molecule converge to apply a change, inspect the result, and then use molecule verify for focused assertions. Before committing, run molecule test. That command resolves dependencies, removes stale resources, creates a clean target, converges the role, applies it again for idempotence, runs verification, and performs final cleanup according to the configured sequence.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand the idempotence phase

Molecule’s idempotence step applies the converge play a second time and checks whether Ansible reports unintended changes. A failure usually indicates that a task rewrites a file, recreates a resource, changes permissions, or otherwise performs work on every run. Investigate the task’s module arguments, file content, ownership, notifications, and conditionals. Some tasks are intentionally non-idempotent or report changes for external reasons; if so, document the reason and isolate that behavior rather than blindly disabling the check.

Debug a failing test without losing the target

  1. Run the failing command with Molecule’s --debug option and use the installed tool’s supported verbosity controls when Ansible output is insufficient.
  2. Run molecule list to determine whether the failure occurred during creation, convergence, verification, or cleanup.
  3. If the instance was destroyed, recreate it with molecule create and repeat the smallest failing phase.
  4. Use molecule login to inspect files, packages, services, users, mounts, and logs inside the target.
  5. Re-run molecule converge after correcting the role or scenario, then run molecule verify.
  6. Finish with molecule destroy when the investigation is complete.

When a full test fails and you need the failed instance to remain available, run molecule test --destroy=never. This is particularly useful for failures in verify.yml: the role has already converged, so you can inspect the exact state that caused the assertion to fail. Remember that retaining resources can consume disk, memory, cloud quota, or money; destroy them explicitly after collecting evidence.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Diagnose by lifecycle stage

  • Dependency failure: check collection names, connectivity to the configured collection source, and whether the environment uses the intended Python interpreter.
  • Create failure: inspect the driver, image or platform definition, permissions, registry access, and container or VM runtime.
  • Converge failure: read the Ansible task error first, then verify inventory group names, role discovery, variables, privilege escalation, and target prerequisites.
  • Idempotence failure: identify the task that reports changes on the second run and correct its state handling.
  • Verify failure: inspect the target directly and decide whether the role or the assertion misstates the intended contract.
  • Destroy failure: remove orphaned resources with the driver’s own tools and then correct the scenario cleanup configuration.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test more than one Ubuntu or input combination

Create additional scenario directories when the role has materially different inputs, operating systems, drivers, or deployment assumptions. Each scenario normally owns its own resources and creates and destroys them independently. This keeps failures isolated, at the cost of additional setup time.

For a matrix, vary one meaningful axis at a time: the target image, connection driver, privilege model, or role variables. The exact image tags and supported combinations must come from your project’s compatibility policy; Molecule’s documentation does not establish a universal Ubuntu image matrix. Record the tested combinations in project documentation and keep them aligned with the versions supported by the role.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use shared state deliberately

With shared_state: true, the default scenario owns resource creation and destruction. Other scenarios reuse that instance for their converge, idempotence, and verify phases. Shared state can reduce expensive provisioning, but it couples scenarios and allows one scenario’s changes to affect another. Use it only when the scenarios are intentionally testing components on the same base instance. Otherwise, let every scenario create a clean target.

Choose the right test approach

Decision axis Disposable container Virtual machine or external target
Isolation Fast, local, and easy to recreate; kernel-level behavior may differ from a host. Closer to a full operating system or production topology; provisioning is slower and more complex.
Cost Usually limited to local compute and storage. May consume hypervisor, cloud, licensing, or network resources.
Feedback speed Well suited to repeated converge and verify loops. Useful when the role depends on system services, kernels, or topology unavailable in a container.
State ownership Normally scenario-local and disposable. Must be carefully isolated or explicitly shared to avoid changing real systems.
Best assertions Files, packages, users, services, permissions, and configuration. Those checks plus boot behavior, networking, storage, system integration, or provider-specific effects.

The driver is an implementation choice, not the test itself. Keep the role contract and assertions identical where possible, then add platform-specific preparation only when the target genuinely differs.

Common mistakes and fixes

  • Running Molecule outside the role: change into the role root so the scenario and role path resolve together.
  • Using a different inventory group: make the group in hosts.yml match hosts: molecule in both playbooks.
  • Assuming the generated scenario is complete: review every generated file, especially the driver, platform, inventory, and test sequence.
  • Putting assertions in converge: move end-state checks to verify.yml so application and verification failures remain distinct.
  • Testing only a reused instance: run the full molecule test lifecycle before committing to expose missing creation-time prerequisites.
  • Ignoring idempotence: treat second-run changes as a role defect or document a narrowly justified exception.
  • Leaving failed infrastructure running: use --destroy=never only while investigating, then destroy the instance and any external resources.
  • Hard-coding an unapproved platform image: select an image and tag supported by the repository’s compatibility policy instead of assuming one Ubuntu release represents all deployments.
  • Overly weak verification: assert the role’s externally visible contract, including ownership, mode, service state, and configuration values where those are part of the contract.
  • Overly brittle verification: avoid asserting incidental implementation details that can change without changing the role’s promised behavior.

A practical workflow

  1. Install and verify Ansible, Molecule, and the selected driver on Ubuntu using the versions approved by the project.
  2. Initialize molecule/default from the role root.
  3. Declare required driver collections in requirements.yml.
  4. Configure the driver, platform, inventory, role path, and lifecycle sequence in molecule.yml.
  5. Write a focused converge.yml that includes the role under test.
  6. Write deterministic assertions in verify.yml.
  7. Use molecule converge while developing and molecule verify for rapid checks on an existing instance.
  8. Run molecule test from a clean state before merging.
  9. When a test fails, preserve the instance with --destroy=never, inspect it with molecule login, and clean up explicitly.
  10. Add separate scenarios for genuinely different platforms or inputs, using shared state only when resource reuse is intentional.

This workflow gives an Ubuntu-based developer a repeatable, inspectable test for both role application and the state the role promises to produce, without confusing the host operating system with the system being managed.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.