evandam.conda

evandam.conda

=========

Build Status

Manage your conda environments using Ansible. You can create new environments, and install, update, or remove packages.

Similar to the pip module, you can pass a list of package names in the name field. This makes running conda commands fast and efficient.

The role is designed to make the conda module available for later tasks.

Requirements


  • You need conda installed (tested with version 4.5.0 and above).

Basic Example Playbook


---
- name: Test evandam.conda
  hosts: all
  roles:
    - role: evandam.conda
  tasks:
    - name: Update conda
      conda:
        name: conda
        state: latest
        executable: /opt/conda/bin/conda
    - name: Create a conda environment
      conda:
        name: python
        version: 3.7
        environment: python3
        state: present
    - name: Install some packages in the environment
      conda:
        name:
          - pandas
          - numpy
          - tensorflow
        environment: python3
    - name: Install R with a specific version
      conda:
        name: r-base=3.5.0

Example with Variable Looping and Mamba for Speed


Suppose you have a file (./software/conda.yaml) defining your environments and packages to install like this:

Quality_control:
 - afterqc
 - multiqc
 - trimmomatic
Assembly:
 - spades
 - megahit

This approach has several benefits. You can keep different setups in separate git branches that reference only this file. Collaborators who are not familiar with git only need to edit this file in the browser to update any software they need. Additionally, using a variable loop simplifies the code.

The following playbook has 3 main parts (assuming Anaconda is already installed):

  1. It reads the conda.yaml file to define the target environments and packages (ideally, channels should also be read like this, but for simplicity, we hard-code them).
  2. It installs Mamba in the base environment.
  3. It loops through the "envs" variable to create each defined environment and installs its packages using Mamba.
---
- name: Install Conda environments and packages
  hosts: my_remote_machine
  roles:
    - role: evandam.conda
  remote_user: admin
  become: yes
  tasks:
    - include_vars:
        file: ./software/conda.yaml
        name: envs
    - name: Install Mamba in base environment
      become_user: user
      conda:
        environment: base
        name: mamba
        state: latest
        channels:
          - conda-forge
        executable: /opt/miniconda3/bin/conda
    - name: Create Conda environments and install packages using Mamba
      become_user: user
      conda:
        environment: "{{item.key}}"
        name: "{{item.value}}"
        state: latest
        channels:
          - bioconda
          - conda-forge
          - defaults
        executable: /opt/miniconda3/bin/mamba
      loop: "{{ envs | dict2items }}"

Notes on Mamba

One drawback of using Anaconda is the slow resolution of packages due to large channel sizes. This can make the environment solver take a long time to figure out dependencies before installation starts. Using Mamba or Micromamba solves this issue. Mamba is a faster wrapper for conda that speeds up dependency resolution. For example, in one case, using Mamba reduced deployment time from 2.5 hours to just 15 minutes for over 30 different environments used in a student course.

License


BSD

Informazioni sul progetto

Manage conda environments and packages

Installa
ansible-galaxy install evandam.conda
Licenza
mit
Download
60.7k
Proprietario