Skip to main content

Molecule driver for Lima VM - Test Ansible roles on macOS Apple Silicon and Linux

Project description

Molecule Lima Driver

PyPI version Python versions License

A Molecule driver for Lima VM, enabling testing of Ansible roles on macOS (Apple Silicon) and Linux with native virtualization support.

Features

  • 🚀 Native Apple Silicon Support - Uses VZ framework for optimal performance on ARM Macs
  • 🐧 Cross-Platform - Works on macOS (Apple Silicon/Intel) and Linux
  • Fast - Lightweight virtualization with minimal overhead
  • 🔧 Flexible - Extensive configuration options for CPU, memory, disk, and networking
  • 📦 Cloud Images - Support for Ubuntu, Debian, Rocky Linux, and other distributions
  • 🎯 Molecule Native - Seamless integration with Molecule testing workflow

Requirements

  • Operating System: macOS (Apple Silicon/Intel) or Linux
  • Lima: >= 0.17.0
  • Python: >= 3.9
  • Ansible: >= 2.12
  • Molecule: >= 6.0.0

Installation

Install Lima

macOS (Homebrew):

brew install lima

Linux:

# Download the latest release
wget https://github.com/lima-vm/lima/releases/latest/download/lima-$(uname -m).tar.gz
tar -xzf lima-$(uname -m).tar.gz
sudo install -m 755 bin/limactl /usr/local/bin/

Install Molecule Lima Driver

pip install molecule-lima

Development Installation:

git clone https://github.com/filatof/molecule-lima.git
cd molecule-lima
pip install -e .[dev]

Quick Start

Initialize a New Scenario

molecule init scenario --driver-name molecule-lima

Basic Configuration

Create or update molecule/default/molecule.yml:

driver:
  name: lima
  ssh_timeout: 180

platforms:
  - name: ubuntu-22-04
    image: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img"
    arch: aarch64
    vm_type: vz  # vz for Apple Silicon, qemu for Intel/Linux
    cpus: 2
    memory: 2GiB
    disk: 20GiB

provisioner:
  name: ansible

verifier:
  name: ansible

Run Tests

# Create instances
molecule create

# Run converge
molecule converge

# Test idempotence
molecule idempotence

# Run verification
molecule verify

# Full test cycle
molecule test

Configuration Options

Platform Parameters

Parameter Description Default Required
name Instance name - Yes
image OS image URL - Yes
arch Architecture (aarch64, x86_64) aarch64 No
vm_type VM type (vz, qemu) vz No
cpus Number of CPUs 2 No
memory RAM amount 2GiB No
disk Disk size 20GiB No
python_interpreter Python path /usr/bin/python3 No
provision_script Provisioning bash script - No
mounts Additional mount points - No

VM Type Selection

  • vz (Virtualization.framework) - Recommended for Apple Silicon Macs (faster, native)
  • qemu - For Intel Macs and Linux systems

Advanced Configuration Example

driver:
  name: lima
  ssh_timeout: 240

platforms:
  # Docker host for container testing
  - name: docker-host
    image: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img"
    arch: aarch64
    vm_type: vz
    cpus: 4
    memory: 4GiB
    disk: 30GiB
    python_interpreter: /usr/bin/python3
    provision_script: |
      apt-get update
      apt-get install -y docker.io python3-pip
      systemctl enable --now docker
      usermod -aG docker $USER
    mounts:
      - location: "/Users/username/project"
        writable: true

  # Multi-platform testing
  - name: debian-12
    image: "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-arm64.qcow2"
    arch: aarch64
    cpus: 2
    memory: 2GiB

  - name: rocky-9
    image: "https://download.rockylinux.org/pub/rocky/9/images/aarch64/Rocky-9-GenericCloud-Base.latest.aarch64.qcow2"
    arch: aarch64
    cpus: 2
    memory: 2GiB

Supported OS Images

Ubuntu ARM64

  • 22.04 (Jammy): https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img
  • 20.04 (Focal): https://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-arm64.img

Debian ARM64

  • 12 (Bookworm): https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-arm64.qcow2
  • 11 (Bullseye): https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-arm64.qcow2

Rocky Linux ARM64

  • 9: https://download.rockylinux.org/pub/rocky/9/images/aarch64/Rocky-9-GenericCloud-Base.latest.aarch64.qcow2

Note: For Intel/x86_64 systems, use corresponding x86_64 images by replacing arm64/aarch64 with amd64/x86_64 in URLs.

Use Cases

Testing Docker-Based Roles

platforms:
  - name: docker-test
    image: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img"
    cpus: 4
    memory: 4GiB
    provision_script: |
      curl -fsSL https://get.docker.com | sh
      systemctl start docker

Multi-Distribution Testing

platforms:
  - name: ubuntu-latest
    image: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img"
  
  - name: debian-stable
    image: "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-arm64.qcow2"
  
  - name: rocky-latest
    image: "https://download.rockylinux.org/pub/rocky/9/images/aarch64/Rocky-9-GenericCloud-Base.latest.aarch64.qcow2"

Troubleshooting

SSH Connection Timeout

Increase ssh_timeout in driver configuration:

driver:
  name: lima
  ssh_timeout: 300  # 5 minutes

Lima Instance Not Starting

Check Lima status:

limactl list
limactl validate /path/to/lima-config.yaml

Image Download Issues

Verify image URL is accessible:

curl -I <image-url>

Performance on Apple Silicon

Ensure you're using vm_type: vz for best performance:

platforms:
  - name: instance
    vm_type: vz  # Native Apple Silicon virtualization

License

MIT License - see LICENSE file for details.

Acknowledgments

  • Molecule - Ansible testing framework
  • Lima - Linux virtual machines on macOS
  • Ansible - Automation platform

Links

Support

If you encounter any issues or have questions:

  1. Check the Troubleshooting section
  2. Search existing issues
  3. Open a new issue with detailed information

Made with ❤️ for the Ansible and DevOps community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

molecule_lima-0.0.2.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

molecule_lima-0.0.2-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file molecule_lima-0.0.2.tar.gz.

File metadata

  • Download URL: molecule_lima-0.0.2.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for molecule_lima-0.0.2.tar.gz
Algorithm Hash digest
SHA256 86e651a354169dab70035f62d6fe58f7611f6978a5597fd0d5d3aa39b07641ca
MD5 4a42c88d9aefbaf390316dab0a1957b4
BLAKE2b-256 e4ae5dfcf51445363cb68ccade4822d736a4cb6f6ef5076be1477cf4ef1919f2

See more details on using hashes here.

File details

Details for the file molecule_lima-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: molecule_lima-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for molecule_lima-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 92966ef7625ee9932e0788bfa56c7fe711279267dbac3d0d7367bf1501fc0496
MD5 f2afcc6b6fc70d3eea60fdfb64d8c9ce
BLAKE2b-256 8b3f24bbefda9d165a3aead2a799f4b87fd12281e36bdf7a1b645dea77b8d774

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page