CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-molecule

Molecule aids in the development and testing of Ansible roles

Pending
Overview
Eval results
Files

cli-commands.mddocs/

CLI Commands

Molecule provides a comprehensive command-line interface for managing the complete lifecycle of Ansible role testing, from initialization through destruction of test environments.

Capabilities

Main CLI Entry Point

The primary entry point for all Molecule operations, providing global options and command routing.

def main(ctx, debug, verbose, base_config, env_file):
    """
    Molecule aids in the development and testing of Ansible roles.
    
    Args:
        ctx (click.Context): Click context object
        debug (bool): Enable or disable debug mode. Default is disabled
        verbose (int): Increase Ansible verbosity level. Default is 0
        base_config (list[str]): Path to base config files (can be multiple)
        env_file (str): File to read variables from when rendering molecule.yml (.env.yml)
    """

Lifecycle Commands

Core commands for managing the test instance lifecycle.

def create():
    """Create test instances using the configured driver."""

def prepare():
    """Run the prepare playbook to set up test instances."""

def converge():
    """Run the converge playbook to apply the role being tested."""

def verify():
    """Run verification tests using the configured verifier."""

def destroy():
    """Destroy test instances and clean up resources."""

def cleanup():
    """Run cleanup tasks and remove temporary files."""

Test Commands

Commands for running various types of tests and validations.

def test():
    """
    Run the full test sequence.
    
    Executes: dependency → create → prepare → converge → 
             idempotence → side_effect → verify → cleanup → destroy
    """

def check():
    """Run the check playbook to validate syntax and configuration."""

def syntax():
    """Validate Ansible playbook syntax using ansible-playbook --syntax-check."""

def idempotence():
    """
    Test role idempotence by running converge twice.
    
    Verifies that the role doesn't make changes on subsequent runs.
    """

def side_effect():
    """Run the side effect playbook for additional testing scenarios."""

Management Commands

Commands for managing scenarios, dependencies, and getting information.

def init():
    """Initialize new Molecule scenarios or roles with default templates."""

def list_():
    """List available scenarios and their current status."""

def matrix():
    """Display the test matrix showing which scenarios run which steps."""

def dependency():
    """Install role dependencies using the configured dependency manager."""

def drivers():
    """List available drivers and their capabilities."""

def reset():
    """Reset Molecule state by clearing cached data and configurations."""

Interactive Commands

Commands for interactive debugging and exploration.

def login():
    """
    Login to a test instance for interactive debugging.
    
    Args:
        host (str): Hostname of the instance to login to
        
    Provides an interactive shell session on the specified test instance.
    """

Usage Examples

Basic Command Usage

# Initialize a new role with molecule
molecule init role my-role --driver-name default

# Run the complete test suite
molecule test

# Run individual lifecycle steps
molecule create
molecule converge  
molecule verify
molecule destroy

# Debug mode with increased verbosity
molecule --debug -vvv test

# Use custom configuration
molecule -c custom-config.yml test

# Test specific scenario
molecule test -s integration-tests

# Login to a test instance for debugging
molecule login --host instance-1

Multi-Scenario Testing

# List all scenarios
molecule list

# Show test matrix
molecule matrix

# Test all scenarios
molecule test --all

# Test with parallel execution
molecule test --parallel

Custom Configuration

# Use custom environment file
molecule -e custom.env.yml test

# Use multiple base configs
molecule -c base.yml -c override.yml test

# Test with custom destroy strategy
molecule test --destroy never

Command Options

Global Options

  • --debug/--no-debug: Enable debug mode for detailed logging
  • -v, --verbose: Increase Ansible verbosity (can be repeated: -vvv)
  • -c, --base-config: Path to base configuration files (multiple allowed)
  • -e, --env-file: Environment file for variable substitution
  • --version: Show version information and exit

Common Command Options

  • -s, --scenario-name: Target specific scenario
  • --driver-name: Override driver for the operation
  • --platform-name: Target specific platform
  • --force: Force execution even with warnings
  • --parallel: Enable parallel execution where supported

Test Command Options

  • --destroy: Destroy strategy ("always" or "never")
  • --all: Test all scenarios
  • --scenario-name: Test specific scenario only

Integration Notes

  • Commands use Click framework for argument parsing and validation
  • Global options are passed through context to individual commands
  • Verbosity settings affect both Molecule and Ansible output levels
  • Configuration files support YAML format with environment variable substitution
  • Command execution follows dependency chains and validates prerequisites

Install with Tessl CLI

npx tessl i tessl/pypi-molecule

docs

cli-commands.md

configuration.md

core-api.md

driver-system.md

exceptions.md

index.md

verifier-system.md

tile.json