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 <scenario-name>

Basic Configuration

Create or update molecule/default/molecule.yml:

driver:
  name: molecule-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
  config_options:
    defaults:
      callbacks_enabled: profile_tasks,timer
      stdout_callback: yaml
      host_key_checking: false

verifier:
  name: ansible

Run Tests

# Create instances
molecule create

# Run converge
molecule converge

# Run verification
molecule verify

# Run idempotence
molecule idempotence

# 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: molecule-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: molecule-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.

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.3.tar.gz (12.0 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.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: molecule_lima-0.0.3.tar.gz
  • Upload date:
  • Size: 12.0 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.3.tar.gz
Algorithm Hash digest
SHA256 ef96c66a6f0ede6c04b67493618805ea24c63a2b3e1d307768f6210d317b6271
MD5 b7954b440cd4fb047c08b6c7f92ef845
BLAKE2b-256 e94f541f13272b6a62b05742af46048ccff5ca44112c4aab49a4820125c5d574

See more details on using hashes here.

File details

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

File metadata

  • Download URL: molecule_lima-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.2 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b9047650478e5511c239fece09de62861dc2d60126b31cd542bcedd63253831b
MD5 ef56692b9401cff13a47114ea8e8d6e8
BLAKE2b-256 7f4a51d5a83c753e098286cbd3bfaf6aac345ebe4267dddf47f3ffa70f1fe6df

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