Skip to content
Snippets Groups Projects
README.md 2.59 KiB
Newer Older
# ics-ans-role-conda
Benjamin Bertrand's avatar
Benjamin Bertrand committed

Ansible role to install `conda` on CentOS and Debian.
`mamba` is also installed by default.
Benjamin Bertrand's avatar
Benjamin Bertrand committed

This role includes as well:
- a `conda` module that can be used to manage conda packages.
- a `conda_env` module that can be used to manage conda environments.
Benjamin Bertrand's avatar
Benjamin Bertrand committed

## Role Variables
Benjamin Bertrand's avatar
Benjamin Bertrand committed

See [defaults/main.yml](defaults/main.yml)
The role can create conda environments if you pass a list of yaml environment files via
the `conda_env_files` variable.
You can use both local files and http/https url:

```yaml
conda_env_files:
  - "{{ playbook_dir }}/config/molecule_env.yml"
  - https://gitlab.esss.lu.se/ics-infrastructure/conda-environments/raw/master/molecule_env.yml
Note that this is deprecated as it has some drawbacks:
- the update is only based on the file content (via a handler) and not the environment itself
- handler can't be used when using `include_role`

Using the `conda_env` module is the recommended way.

## conda module
Benjamin Bertrand's avatar
Benjamin Bertrand committed

The `conda` module allows to install, update or remove conda packages.
`mamba` is used by default. Set `use_mamba: false` to use `conda` instead.
```yaml
Benjamin Bertrand's avatar
Benjamin Bertrand committed
- name: install flask 1.0 and Python 3.7
  conda:
    name:
      - python=3.7
      - flask=1.0
    state: present
    environment: myapp

- name: install flask from conda-forge
  conda:
    name: flask
    state: present
    environment: flaskapp
    channels:
      - conda-forge

- name: update flask to the latest version
  conda:
    name: flask
    state: latest
    environment: myapp

- name: update conda to the latest version
  conda:
    name: conda
    state: latest

- name: remove flask from myapp environment
  conda:
    name: flask
    state: absent
    environment: myapp
```

## conda_env module

The `conda_env` module allows to create, update or remove conda environments.
Using `mamba` with this module isn't supported yet.

```yaml
- name: create myenv environment
  conda_env:
    name: myenv
    state: present
    file: /tmp/environment.yml

- name: update all packages in myenv environment
  conda_env:
    name: myenv
    state: latest

- name: update myenv environment based on environment.yml
  conda_env:
    name: myenv
    state: present
    prune: true
    file: /tmp/environment.yml

- name: force the environment creation (remove previous one first)
  conda_env:
    state: present
    force: true
    file: /tmp/environment.yml

- name: remove myenv environment
  conda_env:
    name: myenv
    state: absent
```

Note that the environment.yml file shall be present locally on the host.
Benjamin Bertrand's avatar
Benjamin Bertrand committed

## Example Playbook
Benjamin Bertrand's avatar
Benjamin Bertrand committed

```yaml
- hosts: servers
  roles:
    - role: ics-ans-role-conda
## License
Benjamin Bertrand's avatar
Benjamin Bertrand committed

BSD 2-clause