mambaorg.micromamba

Ansible Role: mambaorg.micromamba

This role installs micromamba and can also create a conda environment called root/base.

Motivation

Conda is a powerful tool for managing Python dependencies. However, its dependency solver can be very slow and take a long time for many dependencies.

The Mamba project offers a fast alternative by rewriting the dependency solver in C++. Most tasks are still handled by the reliable conda tool.

Micromamba is an experimental package manager for conda environments, written completely in C++. It doesn't require Python to run, allowing it to create environments for any Python version just with a single micromamba binary. If your conda packages don’t need Python, Micromamba can create a conda environment without it!

Micromamba removes the need for large distributions like Anaconda or Miniconda; you can directly set up your desired environment.

Role Variables

arch: linux-64
version: latest

To check the latest architecture and version numbers, visit the Anaconda API. Current values for arch include linux-64, linux-aarch64, osx-64, osx-arm64, and win-64. The version can be latest or something like 0.15.2-0, where -0 indicates the build number.


dest: /usr/local/bin/micromamba

This specifies where the micromamba executable will be located.


root_prefix: /opt/conda

If this path for the root prefix doesn’t exist, it will be created here.


packages:
  - mamba
  - python=3.9

This is a list of conda packages to install when creating a new root prefix.


file: /tmp/environment.yaml

Alternatively, you can provide an environment or lock file instead of a package list.


root_prefix_condarc:
  channels:
    - conda-forge

This defines the content for the .condarc file in the new root prefix. If it's not set, no .condarc file is made.

Example Playbooks

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

This installs the micromamba executable to /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 installs micromamba in /tmp/micromamba and creates 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 creates a new root prefix at /home/conda-user/micromamba and the environment will not include Python. It also adds a .condarc file in the root prefix to use the conda-forge channel by default.

Subsequent Usage

To use commands from a conda environment, it needs to be activated. Activation changes the PATH and other environment variables in the active shell.

Directly

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

The first command sets up a Bash function named micromamba. The second command activates the environment at /opt/conda.

With an initialization script

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

This command modifies ~/.bashrc so that you can simply run micromamba activate in new Bash sessions to activate the environment.

With mamba or conda

Since micromamba is experimental, it's better to install mamba in the environment and run:

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

These commands update ~/.bashrc so that the environment activates in future interactive Bash sessions.

Troubleshooting

If Bash is not interactive, .bashrc won’t be sourced, so micromamba activate will fail. You can either use the direct activation method or run Bash interactively with the -i flag.

License

MIT

Author Information

This role is currently maintained by Ben Mares (@maresb) and Andreas Trawoeger (@atrawog), with initial contributions from @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
606
Proprietario
Mathematician, Freelancer