Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • lucasmagalhaes/ics-ans-role-conda
  • alexthibault-ferial/ics-ans-role-conda
  • andersharrisson/ics-ans-role-conda
  • roryclarke/ics-ans-role-conda
  • rosselliot/ics-ans-role-conda
  • ics-ansible-galaxy/ics-ans-role-conda
6 results
Show changes
---
- name: make sure conda environments don't exist
file:
path: "{{ conda_path }}/envs/{{ item }}"
state: absent
loop:
- myenv
- myenv1
- myenv2
- name: copy environment.yml files
copy:
src: "{{ item }}"
dest: "/tmp/{{ item }}"
loop:
- environment_python371.yml
- environment_python373.yml
- name: create myenv environment
conda_env:
name: myenv
file: /tmp/environment_python371.yml
register: myenv_creation
- name: verify we recorded a change
assert:
that:
- myenv_creation.changed
- name: check Python version in the created environment
command: "{{ conda_path }}/envs/myenv/bin/python --version"
register: python_version
- name: verify Python 3.7.1 was installed
assert:
that:
- "'Python 3.7.1' in python_version.stdout"
- name: update myenv with the same environment.yml file
conda_env:
name: myenv
file: /tmp/environment_python371.yml
register: myenv_update1
- name: verify we didn't recorded a change
assert:
that:
- not myenv_update1.changed
- name: force myenv creation with the same environment.yml file
conda_env:
name: myenv
force: true
file: /tmp/environment_python371.yml
register: myenv_force1
- name: verify we recorded a change
assert:
that:
- myenv_force1.changed
- name: update myenv with a new environment.yml file
conda_env:
name: myenv
file: /tmp/environment_python373.yml
register: myenv_update2
- name: verify we recorded a change
assert:
that:
- myenv_update2.changed
- name: check Python version in the updated environment
command: "{{ conda_path }}/envs/myenv/bin/python --version"
register: python_version
- name: verify Python 3.7.3 was installed
assert:
that:
- "'Python 3.7.3' in python_version.stdout"
- name: delete myenv
conda_env:
name: myenv
state: absent
register: delete_myenv
- name: verify we recorded a change
assert:
that:
- delete_myenv.changed
- name: check if myenv exists
stat:
path: "{{ conda_path }}/envs/myenv"
register: myenv_stat
- name: verify that myenv was removed
assert:
that:
- not myenv_stat.stat.exists
- name: delete myenv again
conda_env:
name: myenv
state: absent
register: delete_myenv2
- name: verify we didn't recorded a change
assert:
that:
- not delete_myenv2.changed
- name: create myenv1 environment without name
conda_env:
file: /tmp/environment_python371.yml
register: myenv1_creation
- name: verify we recorded a change
assert:
that:
- myenv1_creation.changed
- name: update all myenv1 packages
conda_env:
name: myenv1
state: latest
register: myenv1_update1
- name: verify we recorded a change
assert:
that:
- myenv1_update1.changed
- name: update all myenv1 packages again
conda_env:
name: myenv1
state: latest
register: myenv1_update2
- name: verify we didn't record a change
assert:
that:
- not myenv1_update2.changed
import pytest
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
def test_conda_version(host):
cmd = host.run('/opt/conda/bin/conda --version 2>&1')
cmd = host.run("/opt/conda/bin/conda --version 2>&1")
assert cmd.rc == 0
assert cmd.stdout.strip() == 'conda 4.6.12'
assert cmd.stdout.strip() == "conda 23.11.0"
def test_conda_path(host):
cmd = host.run('su -l -c "type conda" root')
assert cmd.stdout.startswith('conda is a function')
assert cmd.stdout.startswith("conda is a function")
def test_mamba_version(host):
cmd = host.run("/opt/conda/bin/mamba --version 2>&1")
assert cmd.rc == 0
assert "mamba 1.5.5" in cmd.stdout.strip()
def test_mamba_path(host):
cmd = host.run('su -l -c "type mamba" root')
assert cmd.stdout.startswith("mamba is a function")
def test_condarc_file(host):
condarc = host.file("/opt/conda/.condarc")
if host.ansible.get_variables()["inventory_hostname"] == "ics-ans-role-conda-rpm":
assert condarc.content_string == """channel_alias: https://artifactory.esss.lu.se/artifactory/api/conda
if (
host.ansible.get_variables()["inventory_hostname"].startswith("ics-ans-role-conda-rpm")
):
assert (
condarc.content_string.strip()
== """channel_alias: https://artifactory.esss.lu.se/artifactory/api/conda
channels:
- conda-forge
auto_update_conda: False"""
default_channels: []
auto_update_conda: False
use_only_tar_bz2: False"""
)
else:
assert condarc.content_string == """channel_alias: https://artifactory.esss.lu.se/artifactory/api/conda
assert (
condarc.content_string.strip()
== """channel_alias: https://artifactory.esss.lu.se/artifactory/api/conda
channels:
- ics-conda
- conda-e3
- ics-conda-forge
- conda-forge
- anaconda-main
auto_update_conda: False"""
default_channels: []
auto_update_conda: False
use_only_tar_bz2: False"""
)
def test_condaz_default_env_file(host):
condaz_default_env = host.file("/etc/profile.d/condaz_default_env.sh")
if (
host.ansible.get_variables()["inventory_hostname"].startswith("ics-ans-role-conda-create-env")
) or (
host.ansible.get_variables()["inventory_hostname"]
== "ics-ans-role-conda-create-env-ess-linux"
):
assert (
condaz_default_env.content_string.strip()
== r"""export PS1='[\u@\h \W]\$ '
conda activate python36"""
)
else:
assert not condaz_default_env.exists
@pytest.mark.parametrize("name", ["/opt/conda", "/opt/conda/envs", "/opt/conda/pkgs"])
def test_conda_owner(host, name):
if (
host.ansible.get_variables()["inventory_hostname"].startswith("ics-ans-role-conda-create-env")
) or (
host.ansible.get_variables()["inventory_hostname"]
== "ics-ans-role-conda-create-env-ess-linux"
):
user = "vagrant"
group = "vagrant"
else:
user = "root"
group = "root"
assert host.file(name).user == user
assert host.file(name).group == group
......@@ -3,16 +3,17 @@ import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('ics-ans-role-conda-create-env')
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("ics-ans-role-conda-create-env*")
def test_conda_env_python36(host):
assert host.file('/opt/conda/envs/python36/bin').exists
cmd = host.run('/opt/conda/envs/python36/bin/python --version 2>&1')
assert cmd.stdout.startswith('Python 3.6')
assert host.file("/opt/conda/envs/python36/bin").exists
cmd = host.run("/opt/conda/envs/python36/bin/python --version 2>&1")
assert cmd.stdout.startswith("Python 3.6")
def test_conda_env_python27(host):
assert host.file('/opt/conda/envs/python27/bin').exists
cmd = host.run('/opt/conda/envs/python27/bin/python --version 2>&1')
assert cmd.stdout.startswith('Python 2.7')
assert host.file("/opt/conda/envs/python27/bin").exists
cmd = host.run("/opt/conda/envs/python27/bin/python --version 2>&1")
assert cmd.stdout.startswith("Python 2.7")
# Custom Dockerfile template for ESS Linux
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN dnf makecache && dnf --assumeyes install iproute2 && dnf clean all
---
dependency:
name: galaxy
lint: |
set -e
yamllint .
ansible-lint
flake8
provisioner:
name: ansible
playbooks:
converge: ../default/converge.yml
prepare: ../default/prepare.yml
side_effect: ../default/side_effect.yml
config_options:
defaults:
callback_whitelist: profile_tasks
gather_timeout: 20
inventory:
group_vars:
conda_create_env:
conda_env_files:
- "{{ playbook_dir }}/tests/python36_env.yml"
- https://gitlab.esss.lu.se/ics-ansible-galaxy/ics-ans-role-conda/raw/master/molecule/default/tests/python27_env.yml
conda_default_env: python36
conda_owner: vagrant
conda_group: vagrant
ess_linux:
ansible_python_interpreter:
"/usr/bin/python3"
scenario:
name: ess-linux
verifier:
name: testinfra
directory: ../default/tests/
driver:
name: docker
platforms:
- name: ics-ans-role-conda-ess-linux
image: registry.esss.lu.se/ics-docker/ess-linux:latest
dockerfile: Dockerfile-ess-linux.j2
capabilities:
- SYS_ADMIN
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
tmpfs:
- /run
- /run/lock
command: /lib/systemd/systemd
groups:
- ess_linux
- name: ics-ans-role-conda-create-env-ess-linux
image: registry.esss.lu.se/ics-docker/ess-linux:latest
dockerfile: Dockerfile-ess-linux.j2
capabilities:
- SYS_ADMIN
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
tmpfs:
- /run
- /run/lock
command: /lib/systemd/systemd
groups:
- ess_linux
- conda_create_env
---
dependency:
name: galaxy
lint: |
set -e
yamllint .
ansible-lint
flake8
provisioner:
name: ansible
playbooks:
converge: ../default/converge.yml
config_options:
defaults:
callback_whitelist: profile_tasks
gather_timeout: 20
inventory:
group_vars:
conda_create_env:
conda_env_files:
- "{{ playbook_dir }}/tests/python36_env.yml"
- https://gitlab.esss.lu.se/ics-ansible-galaxy/ics-ans-role-conda/raw/master/molecule/default/tests/python27_env.yml
conda_default_env: python36
conda_owner: vagrant
conda_group: vagrant
conda_rpm:
conda_channels:
- conda-forge
scenario:
name: ubuntu
verifier:
name: testinfra
directory: ../default/tests/
driver:
name: docker
platforms:
- name: ics-ans-role-conda-default-ubuntu20
image: registry.esss.lu.se/ics-docker/ubuntu-systemd:focal
- name: ics-ans-role-conda-create-env-ubuntu20
image: registry.esss.lu.se/ics-docker/ubuntu-systemd:focal
groups:
- conda_create_env
- name: ics-ans-role-conda-rpm-ubuntu20
image: registry.esss.lu.se/ics-docker/ubuntu-systemd:focal
groups:
- conda_rpm
- name: ics-ans-role-conda-default-ubuntu22
image: registry.esss.lu.se/ics-docker/ubuntu-systemd:22.04
- name: ics-ans-role-conda-create-env-ubuntu22
image: registry.esss.lu.se/ics-docker/ubuntu-systemd:22.04
groups:
- conda_create_env
- name: ics-ans-role-conda-rpm-ubuntu22
image: registry.esss.lu.se/ics-docker/ubuntu-systemd:22.04
groups:
- conda_rpm
---
- name: Prepare ics-ans-role-conda-create-env
hosts: ics-ans-role-conda-create-env*
gather_facts: false
tasks:
- name: create vagrant user
user:
name: vagrant
state: present
- name: Prepare ics-ans-role-conda-rpm
hosts: ics-ans-role-conda-rpm*
gather_facts: false
tasks:
- name: create conda directory
file:
name: /opt/conda
state: directory
- name: create dummy .condarc file
file:
path: /opt/conda/.condarc
state: touch
---
# When using RPM, conda should be updated using yum.
# The issue is that new RPMs currently takes a very long time
# before to be updated/released by anaconda.
# before to be updated/released.
# So we use the default installer for now.
- name: uninstall conda RPM
yum:
package:
name: conda
state: absent
register: conda_rpm_removed
......@@ -23,6 +24,7 @@
name: conda
file: conda
state: absent
when: ansible_os_family == "RedHat"
- name: delete old conda_env.sh file
file:
......
---
- block:
- name: set env_file_path
set_fact:
env_file_path: "/opt/conda/{{ env_file | basename }}"
- name: set env_file_path
set_fact:
env_file_path: "{{ conda_path }}/{{ env_file | basename }}"
tags: conda-env
- name: copy local conda environment file
copy:
src: "{{ env_file }}"
dest: "{{ env_file_path }}"
owner: root
group: root
mode: 0644
when: not env_file | regex_search('^http')
notify:
- create conda environment
- name: copy local conda environment file
copy:
src: "{{ env_file }}"
dest: "{{ env_file_path }}"
owner: "{{ conda_owner }}"
group: "{{ conda_group }}"
mode: 0644
when: not env_file | regex_search('^http')
tags: conda-env
- name: copy conda environment file from url
get_url:
url: "{{ env_file }}"
dest: "{{ env_file_path }}"
force: true
owner: root
group: root
mode: 0644
when: env_file | regex_search('^http')
notify:
- create conda environment
- name: copy conda environment file from url
get_url:
url: "{{ env_file }}"
dest: "{{ env_file_path }}"
force: true
owner: "{{ conda_owner }}"
group: "{{ conda_group }}"
mode: 0644
when: env_file | regex_search('^http')
tags: conda-env
- name: run the handler to create the environment
meta: flush_handlers
- block:
- name: create or update the conda environment
conda_env:
state: present
file: "{{ env_file_path }}"
rescue:
- name: force the creation of the conda environment (update failed)
conda_env:
state: present
force: true
file: "{{ env_file_path }}"
become: true
become_user: "{{ conda_owner }}"
tags: conda-env
---
- name: install required packages
yum:
package:
name:
- bzip2
- sudo
state: present
- name: check if conda is installed
command: /opt/conda/bin/conda --version 2>&1
command: "{{ conda_path }}/bin/conda --version 2>&1"
check_mode: false
failed_when: false
changed_when: false
......@@ -15,48 +15,88 @@
- name: create conda directory
file:
path: /opt/conda
path: "{{ conda_path }}"
state: directory
mode: 0755
owner: root
group: root
owner: "{{ conda_owner }}"
group: "{{ conda_group }}"
- name: download miniconda installer
get_url:
url: "{{ conda_installer_url }}"
checksum: md5:{{ conda_installer_md5 }}
dest: /opt/conda
dest: "{{ conda_path }}"
mode: 0644
when: run_conda_version.rc != 0
- name: install conda
command: >
bash /opt/conda/{{ conda_installer }} -p /opt/conda -b -f
bash {{ conda_path }}/{{ conda_installer }} -p {{ conda_path }} -b -f
become: true
become_user: "{{ conda_owner }}"
when: run_conda_version.rc != 0
- name: create condarc file
template:
src: system_condarc.j2
dest: /opt/conda/.condarc
owner: root
group: root
dest: "{{ conda_path }}/.condarc"
owner: "{{ conda_owner }}"
group: "{{ conda_group }}"
mode: 0644
- name: delete miniconda installer
file:
path: /opt/conda/{{ conda_installer }}
path: "{{ conda_path }}/{{ conda_installer }}"
state: absent
# Always install conda from conda-forge
- name: check conda and mamba versions
command: "{{ conda_path }}/bin/conda list -f --json 'mamba|conda'"
check_mode: false
failed_when: false
changed_when: false
register: conda_version_check
- name: set fact for conda executable
set_fact:
conda_current_conda_version: "{{ ((conda_version_check.stdout | from_json) | selectattr('name','equalto','conda') | list)[0].version }}"
conda_current_mamba_version: "{{ ((conda_version_check.stdout | from_json) | selectattr('name','equalto','mamba') | list)[0].version if ((conda_version_check.stdout | from_json) | selectattr('name','equalto','mamba') | list) else None }}"
conda_executable: "{{ conda_path ~ '/bin/mamba' if (((conda_version_check.stdout | from_json) | selectattr('name','equalto','mamba') | list | length) > 0) else conda_path ~ '/bin/conda' }}"
# Always install conda and mamba from conda-forge
# Specify the conda-forge channel as it might not be in the list
# of channels defined in the system .condarc file
- name: install conda version {{ conda_version }}
- name: install conda version {{ conda_version }} and mamba version {{ conda_mamba_version }}
command: >
/opt/conda/bin/conda install -y -n base -c conda-forge conda={{ conda_version }}
when: (run_conda_version.rc != 0) or (run_conda_version.stdout != "conda " ~ conda_version)
/opt/conda/bin/conda install -y -n base -c conda-forge --update-all python={{ conda_python_version }} conda={{ conda_version }} mamba={{ conda_mamba_version }}
become: true
become_user: "{{ conda_owner }}"
when: (conda_current_conda_version != conda_version) or
(conda_current_mamba_version != conda_mamba_version)
- name: create /etc/profile.d directory
file:
path: '/etc/profile.d'
mode: 0755
owner: root
group: root
state: directory
when: ansible_os_family == 'Concurrent CPU SDK'
- name: create link to conda.sh profile
- name: create link to conda.sh and mamba.sh profile
file:
src: /opt/conda/etc/profile.d/conda.sh
dest: /etc/profile.d/conda.sh
src: "{{ conda_path }}/etc/profile.d/{{ item }}"
dest: /etc/profile.d/{{ item }}
state: link
loop:
- conda.sh
- mamba.sh
# File named condaz_... because it shall be after conda.sh
- name: create profile.d file to activate default env
template:
src: condaz_default_env.sh.j2
dest: /etc/profile.d/condaz_default_env.sh
owner: root
group: root
mode: 0644
when: conda_default_env != "" # noqa 602
......@@ -7,7 +7,7 @@
- name: create conda environment(s)
include_tasks: create_conda_env.yml
with_items: "{{ conda_env_files }}"
loop: "{{ conda_env_files }}"
loop_control:
loop_var: env_file
tags: conda-env
export PS1='[\u@\h \W]\$ '
conda activate {{ conda_default_env }}
......@@ -3,4 +3,6 @@ channels:
{% for channel in conda_channels %}
- {{ channel }}
{% endfor %}
default_channels: []
auto_update_conda: False
use_only_tar_bz2: {{ conda_use_only_tar_bz2 | string }}
---
conda_installer: Miniconda3-4.5.12-Linux-x86_64.sh
conda_installer_md5: 866ae9dff53ad0874e1d1a60b1ad1ef8
conda_installer_url: "https://artifactory.esss.lu.se/artifactory/swi-pkg/anaconda/{{ conda_installer }}"
conda_installer: Miniforge3-23.11.0-0-Linux-x86_64.sh
conda_installer_md5: ee57176f95c313b23850e0221498f8e8
conda_installer_url: "https://artifactory.esss.lu.se/artifactory/swi-pkg/conda/{{ conda_installer }}"
conda_path: /opt/conda