diff --git a/conda/defaults/main.yml b/conda/defaults/main.yml new file mode 100644 index 00000000..66d42a81 --- /dev/null +++ b/conda/defaults/main.yml @@ -0,0 +1,15 @@ +--- +# http://conda.pydata.org/miniconda.html +conda_ver: 2 +conda_installer_file: 'Miniconda{{ conda_ver }}-latest-Linux-x86_64.sh' +conda_url: 'https://repo.continuum.io/miniconda/{{ conda_installer_file }}' +conda_install_prefix: '/srv/conda{{ conda_ver }}' +# Change it to an unprivileged user +conda_user: root + +#conda_environments: +# - { name: '', opts: '' } + +#conda_env_pkgs: +# - { conda_prefix: '{{ conda_install_prefix }}', pkg: '', repo_list: '' } + diff --git a/conda/meta/main.yml b/conda/meta/main.yml new file mode 100644 index 00000000..6a91b6e1 --- /dev/null +++ b/conda/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - role: '../../library/roles/python-env' diff --git a/conda/tasks/main.yml b/conda/tasks/main.yml new file mode 100644 index 00000000..2d9d5e2c --- /dev/null +++ b/conda/tasks/main.yml @@ -0,0 +1,42 @@ +--- +- block: + - name: Find the user home directory path + getent: database=passwd key={{ conda_user }} split=":" + + - name: Create a downloads directory if does not exist + file: dest={{ getent_passwd[conda_user][4] }}/downloads state=directory + + - name: Download the conda installer + get_url: url={{ conda_url }} dest={{ getent_passwd[conda_user][4] }}/downloads mode=0744 + + - name: Run the conda installer + command: '{{ getent_passwd[conda_user][4] }}/downloads/{{ conda_installer_file }} -f -b -p {{ conda_install_prefix }}' + args: + creates: '{{ conda_install_prefix }}/bin/conda' + + become: True + become_user: '{{ conda_user }}' + tags: [ 'python', 'conda' ] + +- block: + - name: Create a conda environment + shell: export PATH={{ conda_install_prefix }}/bin:{{ ansible_env.PATH }} ; conda create -y -n {{ item.name }} {{ item.opts }} + environment: + PATH: 'PATH={{ conda_install_prefix }}/bin:{{ ansible_env.PATH }}' + args: + creates: '{{ conda_install_prefix }}/envs/{{ item.name }}' + with_items: '{{ conda_environments }}' + + - name: Install additional packages and libraries inside the conda environment + shell: export PATH={{ conda_install_prefix }}/bin:{{ ansible_env.PATH }} ; conda install -y {{ item.repo_list }} {{ item.pkg }} ; touch {{ conda_install_prefix }}/.{{ item.pkg }} + environment: + PATH: 'PATH={{ conda_install_prefix }}/bin:{{ ansible_env.PATH }}' + args: + creates: '{{ conda_install_prefix }}/.{{ item.pkg }}' + with_items: '{{ conda_env_pkgs }}' + when: conda_env_pkgs is defined + + become: True + become_user: '{{ conda_user }}' + when: conda_environments is defined + tags: [ 'python', 'conda', 'conda_env' ] diff --git a/conda/vars/main.yml b/conda/vars/main.yml new file mode 100644 index 00000000..a1cc1635 --- /dev/null +++ b/conda/vars/main.yml @@ -0,0 +1,2 @@ +--- +py_env_install: True