mambaorg.micromamba

Ansible Role: mambaorg.micromamba

This role installs micromamba and can create a basic conda environment.

Motivation

Conda is an excellent tool to manage Python dependencies, but it can be very slow with many dependencies, sometimes taking hours to complete.

Mamba solves this problem by rewriting its dependency solver in C++, making it much faster. Mamba uses the reliable conda tool for most other tasks.

Micromamba is a lightweight C++ package manager for conda environments. It has no Python dependencies and can create environments for any Python version from a single binary. If your conda packages don't require Python, Micromamba can even create a conda environment without it!

Micromamba removes the need for full distributions like Anaconda or Miniconda, letting you set up your environment directly.

Role Variables

arch: linux-64
version: latest

Check for the latest architecture and version information. Possible arch values include linux-64, linux-aarch64, osx-64, osx-arm64, win-64. The version can be latest or something like 0.15.2-0.


dest: /usr/local/bin/micromamba

This is where the micromamba executable will be placed.


root_prefix: /opt/conda

If this root prefix doesn't exist, a new one will be created here.


packages:
  - mamba
  - python=3.9

These are the initial conda packages that will be installed when creating a new root prefix.


file: /tmp/environment.yaml

You can also provide an environment file instead of a package list.


root_prefix_condarc:
  channels:
    - conda-forge

The content for the .condarc file in the new root prefix. If not set, the file won't be created.

Example Playbooks

- hosts: servers
  become: yes
  roles:
      - mambaorg.micromamba

This installs the micromamba executable in the default location: /usr/local/bin/micromamba.


- hosts: servers
  become: yes
  roles:
      - mambaorg.micromamba
  vars:
    dest: /tmp/micromamba
    root_prefix: /opt/conda
    packages:
      - mamba
      - python=3.9

This puts micromamba in /tmp/micromamba, creating a new root prefix at /opt/conda/ with Python 3.9 and Mamba.


- hosts: servers
  become: yes
  become_user: condauser
  roles:
      - mambaorg.micromamba
  vars:
    root_prefix: ~/micromamba
    root_prefix_condarc:
      channels:
        - conda-forge
    packages:
      - s3fs-fuse

This sets up a new root prefix at /home/conda-user/micromamba, creating a conda environment without Python. It also creates a .condarc file to install packages from the conda-forge channel by default.

Subsequent Usage

To run commands in a conda environment, it must first be activated. Activation modifies the PATH and other environment variables in the shell (usually Bash).

Directly

eval "$(micromamba shell hook --shell=bash)"
micromamba activate --prefix=/opt/conda

The first command sets up a Bash function named micromamba so it can modify the shell environment. The second command activates the environment at /opt/conda.

With an Initialization Script

micromamba shell init --shell=bash --prefix=/opt/conda

This updates ~/.bashrc so you can use micromamba activate in future sessions to activate the environment.

With Mamba or Conda

Since micromamba is experimental, it’s better to use mamba or conda for activation. Install mamba in the environment and run:

/opt/conda/bin/conda init bash
/opt/conda/bin/mamba init bash

These commands modify ~/.bashrc to fully activate the environment in future sessions.

Troubleshooting

If Bash is not interactive, ~/.bashrc won’t load, and running micromamba activate will fail. In this case, use the direct activation method or start an interactive shell with bash -i.

License

MIT

Author Information

Maintained by Ben Mares (@maresb) and Andreas Trawoeger (@atrawog). Initial version by @maresb. Contributions are welcome!

Informazioni sul progetto

Install micromamba, and optionally create a base conda environment.

Installa
ansible-galaxy install mambaorg.micromamba
Licenza
mit
Download
594
Proprietario