diff --git a/README.md b/README.md index bbd966987a07405f91645a32d9dd7fafab9c17df..a2bae451e11b690da4349edd6af4ed2b752e4cad 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,12 @@ uid automatically generated). The role can create conda environments if you pass a list of yaml environment files via the `conda_env_files` variable. -You could use something like the following in your playbook: +You can use both local files and http/https url: ```yaml conda_env_files: - "{{ playbook_dir }}/config/molecule_env.yml" + - https://artifactory.esss.lu.se/artifactory/swi-pkg/conda/molecule/molecule2_env.yml ``` diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..917fa817e704e4faa55d366cb1c05bc3b924ab35 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: create conda environment + command: "/opt/conda/bin/conda env create --force -f {{ env_file_path }}" + become: true + become_user: conda diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 6be4477aa79d416eae15495ef74ce69b0d940a8f..84f96446fbe72782ca4f6242fbe98226c4ceb62d 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -14,8 +14,8 @@ provisioner: conda_uid: 48 create_env: conda_env_files: - - "{{ playbook_dir }}/tests/python27_env.yml" - "{{ playbook_dir }}/tests/python36_env.yml" + - https://artifactory.esss.lu.se/artifactory/swi-pkg/conda/molecule/molecule_env.yml scenario: name: default verifier: diff --git a/molecule/default/tests/test_conda_create_env.py b/molecule/default/tests/test_conda_create_env.py index b1f6260fc5e86ecdab043403e77fc6e7a2a175df..9f3725925dba81b15d7741010aae2f98dcc82dfa 100644 --- a/molecule/default/tests/test_conda_create_env.py +++ b/molecule/default/tests/test_conda_create_env.py @@ -6,13 +6,13 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('create_env') -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') - - 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') + + +def test_conda_env_molecule(host): + assert host.file('/opt/conda/envs/molecule/bin').exists + cmd = host.run('/opt/conda/envs/molecule/bin/molecule --version 2>&1') + assert cmd.stdout.startswith('molecule, version 1.25.1') diff --git a/tasks/create_conda_env.yml b/tasks/create_conda_env.yml index 66c027fc47db22df8cfd6352854e08f7f8a0a8e3..1b417f89f4dfd407cb3d7a81d10ff9c5b1084c57 100644 --- a/tasks/create_conda_env.yml +++ b/tasks/create_conda_env.yml @@ -1,21 +1,29 @@ --- -- name: copy conda environment file +- name: set env_file_path + set_fact: + env_file_path: "/opt/conda/{{ env_file | basename }}" + +- name: copy local conda environment file copy: src: "{{ env_file }}" - dest: "/opt/conda/{{ env_file | basename }}" + dest: "{{ env_file_path }}" + owner: conda + group: users + mode: 0644 + when: not 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 }}" owner: conda group: users mode: 0644 - register: conda_env + when: env_file | regex_search('^http') + notify: + - create conda environment -# Skip ansible-lint to avoid: -# [ANSIBLE0016] Tasks that run when changed should likely be handlers -# This task is not a handler and should be run now and not at the end -# the play -- name: create conda environment - command: "/opt/conda/bin/conda env create --force -f /opt/conda/{{ env_file | basename }}" - become: true - become_user: conda - when: conda_env.changed - tags: - - skip_ansible_lint +- name: run the handler to create the environment + meta: flush_handlers diff --git a/tasks/main.yml b/tasks/main.yml index a7c712f9cf476042ca7b052b3f742af63c691c62..07c5a44002e63e7bc816c14ec063e61d1c3a093f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -111,3 +111,4 @@ with_items: "{{ conda_env_files }}" loop_control: loop_var: env_file + tags: conda-env