mamba-org/ansible-role-micromamba

Example how to create separate environment is missing

Closed this issue · 1 comments

Hello, this is not a real issue, but perhaps some comments on the examples which do not fit my needs. I want to install a mamba base environment on a remote machine (ubun22orweb) and then a separate environment with a specific list of packages.

I must say that my remote machines are ldx images (kind of virtual machines) so I am not sure what the impact is on that. For me it is required to run the following first:

ansible-galaxy collection install community.general -f

Then I add my hosts in a file host.yml:

--- host.yml file
all:
  vars:
    ansible_connection: lxd
    ansible_user: root
    ansible_become: no
  children:
    local:
      vars:
        ansible_lxd_remote: local
      hosts:
        ubun22ordsk:
        ubun22orweb:

My playbook then look like this:

--- file: mambaweb.yml
- name: Configure ubuntu webserver with mamba
  hosts:
  -  ubun22orweb
  become: yes
  vars:
    user: eelco
    home: "/home/{{ user }}"
    arch: linux-aarch64
    root_prefix: /opt/conda
    root_prefix_condarc:
      channels:
        - conda-forge
    packages:
      - mamba
      - python=3.9
  roles:
  - mambaorg.micromamba
  tasks:
    - name: Change owner Mamba
      file:
        path: "{{ root_prefix }}"
        owner: "{{ user }}"
        group: "{{ user }}"
        recurse: True
    - name: Run Mamba init
      shell: "{{ root_prefix }}/bin/mamba init --system"
      args:
        creates: /etc/profile.d/conda.sh

I run this playbook with the command:

ansible-playbook -i host.yml mambaweb.yml

The extra tasks which I have added are required to change the permissions of the conda root and to initialize the mamba environment. The mamba environment is initialize on a system level. The reason is that I can not use become_user: I always stay root. I think that is related to the variable in my host.yml file which says 'ansible_become: no', but I thought this is required to be able to install on remote ldx images.

Anyway, so far so good: a base mamba environment under /opt/conda is created. When I log in, the mamba environment is automatically loaded.

The thing is: I want to create a new environment with say python 3.10. Normally on a shell you do mamba create -n py310 python=3.10, which will create a new directory under /opt/conda/envs/py310, but I can not find how to do this with your micromamba role. My question is: is there a proper way of creating new environments within the base environment? I should I run shell command from ansible for that?

Hopefully you can point me into the right direction.

sorry, duplicated by accident