diff --git a/.ansible-lint-ignore b/.ansible-lint-ignore new file mode 100644 index 0000000..f3803a4 --- /dev/null +++ b/.ansible-lint-ignore @@ -0,0 +1 @@ +tests/test.yml role-name[path] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 837e90e..f423b0b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,7 +31,7 @@ repos: - id: shell-lint - repo: https://github.com/ansible-community/ansible-lint - rev: v6.0.0 + rev: v6.22.2 hooks: - id: ansible-lint diff --git a/README.md b/README.md index 67dfccb..61686e6 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ None. | Variable | Required | Default | Choices | Comments | |-----------------|----------|------------------|-----------------------------------|---------------------------------------| | python_versions | yes | [3.10.6, 3.9.13] | Array with Python versions >= 3.7 | Version have to be specified as 3.x.y | +| python_jupyter_kernel | no | true | Boolean: true, false | Makes Python available as a Jupyter Kernel | ## Dependencies diff --git a/defaults/main.yml b/defaults/main.yml index 6d2453d..2336078 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,3 +3,4 @@ python_versions: - 3.10.6 - 3.9.13 +python_jupyter_kernel: true diff --git a/molecule/aws-ec2/verify.yml b/molecule/aws-ec2/verify.yml index 42b0c49..b9ad5bf 100644 --- a/molecule/aws-ec2/verify.yml +++ b/molecule/aws-ec2/verify.yml @@ -6,6 +6,6 @@ gather_facts: false pre_tasks: - name: Include vars - include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" - name: Include tasks - include: "{{ playbook_dir }}/../../tests/tasks/post.yml" + ansible.builtin.include_tasks: "{{ playbook_dir }}/../../tests/tasks/post.yml" diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 30b0831..30bf159 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -5,5 +5,8 @@ pre_tasks: - name: Include vars include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" + - name: debug + debug: + var: playbook_dir roles: - - ../../../ + - "{{ playbook_dir }}/../../" diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 49de14c..d8644da 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -4,7 +4,7 @@ become: true pre_tasks: - name: Include vars - include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" tasks: - name: Include tasks - include: "{{ playbook_dir }}/../../tests/tasks/post.yml" + ansible.builtin.include_tasks: "{{ playbook_dir }}/../../tests/tasks/post.yml" diff --git a/tasks/main.yml b/tasks/main.yml index f11ff9d..303627d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -30,3 +30,30 @@ changed_when: "'Successfully installed' in command_result.stdout" tags: - python-install-upgrade-tools + +- name: Install python | Make available as a Jupyter Kernel + when: python_jupyter_kernel + tags: + - python-install-jupyter-kernel + block: + - name: Install python | Install ipykernel + ansible.builtin.pip: + executable: "/opt/python/{{ item }}/bin/pip" + name: ipykernel + loop: "{{ python_versions }}" + + - name: Install python | Check if kernel.json exists + ansible.builtin.stat: + path: "/usr/local/share/jupyter/kernels/py{{ item }}/kernel.json" + loop: "{{ python_versions }}" + register: kernel_json + + - name: Install python | Make available as a Jupyter Kernel + ansible.builtin.command: > + /opt/python/{{ item }}/bin/python -m ipykernel install \ + --name py{{ item }} --display-name "Python {{ item }}" + loop: "{{ python_versions }}" + loop_control: + index_var: index + register: command_result + changed_when: kernel_json.results[index].stat.exists == false diff --git a/tests/test.yml b/tests/test.yml index 5d3d5cf..b0a3df0 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -8,7 +8,7 @@ - name: Include vars ansible.builtin.include_vars: "{{ playbook_dir }}/vars/main.yml" roles: - - ../../ + - "{{ playbook_dir }}/.." post_tasks: - name: Include tasks ansible.builtin.include_tasks: "{{ playbook_dir }}/tasks/post.yml"