Molecule Vagrant Driver

2.0.0 · active · verified Fri Apr 17

Molecule Vagrant is a plugin for the Molecule testing framework, enabling users to provision and test Ansible roles and playbooks on Vagrant-managed virtual machines. It integrates the robust local virtualization capabilities of Vagrant with Molecule's structured testing approach. The current version is 2.0.0, with releases typically aligning with major Molecule updates or significant breaking changes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a Molecule scenario with the Vagrant driver, configure a basic Vagrant box in `molecule.yml`, and execute the Molecule test sequence. Remember that Vagrant and a provider must be installed separately on your system.

# 1. Install Molecule and the Vagrant driver:
# pip install molecule molecule-vagrant

# 2. Ensure Vagrant and a provider (e.g., VirtualBox) are installed system-wide.

# 3. Create a new Molecule project using the vagrant driver:
# molecule init scenario --driver-name vagrant --role-name my-test-role

# 4. Modify the generated molecule.yml to configure your Vagrant box:
# This example uses 'generic/alpine316' for speed and minimal resources.

# --- begin .molecule/my-test-role/molecule.yml ---
# For a real project, replace 'my-test-role' with your actual role name.

# lint: ignore
driver:
  name: vagrant

platforms:
  - name: instance
    box: generic/alpine316
    memory: 256
    cpus: 1
    provider_options:
      memory: 256
      cpus: 1

provisioner:
  name: ansible
  inventory:
    group_vars:
      all:
        ansible_python_interpreter: /usr/bin/python3

verifier:
  name: ansible
# --- end .molecule/my-test-role/molecule.yml ---

# 5. Run your Molecule tests:
# cd my-test-role
# molecule test

view raw JSON →