From d763ae379b9fe0a8735dffca3b03c42aae9ff463 Mon Sep 17 00:00:00 2001 From: koralowiec Date: Tue, 30 Jan 2024 16:06:24 +0100 Subject: [PATCH 1/5] feat: add ability to make Python available as Jupyter Kernel --- README.md | 1 + defaults/main.yml | 1 + tasks/main.yml | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) 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..a915dc8 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 \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index f11ff9d..b16e734 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 + 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 + when: python_jupyter_kernel + tags: + - python-install-jupyter-kernel \ No newline at end of file From a454e4e54c0b33d91fb459e67b72a4e78f318771 Mon Sep 17 00:00:00 2001 From: koralowiec Date: Wed, 31 Jan 2024 09:03:02 +0100 Subject: [PATCH 2/5] chore: bump version of ansible-lint pre-commit hook --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 6c05449eacd388670bfe49daa32f07da2fbcb3b1 Mon Sep 17 00:00:00 2001 From: koralowiec Date: Wed, 31 Jan 2024 09:04:58 +0100 Subject: [PATCH 3/5] chore: fix lint errors --- defaults/main.yml | 2 +- tasks/main.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index a915dc8..2336078 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,4 +3,4 @@ python_versions: - 3.10.6 - 3.9.13 -python_jupyter_kernel: true \ No newline at end of file +python_jupyter_kernel: true diff --git a/tasks/main.yml b/tasks/main.yml index b16e734..303627d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -32,6 +32,9 @@ - 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: @@ -54,6 +57,3 @@ index_var: index register: command_result changed_when: kernel_json.results[index].stat.exists == false - when: python_jupyter_kernel - tags: - - python-install-jupyter-kernel \ No newline at end of file From 5624238257580e9d70c1204fac24e48df1c88424 Mon Sep 17 00:00:00 2001 From: koralowiec Date: Wed, 31 Jan 2024 09:17:31 +0100 Subject: [PATCH 4/5] chore: replace deprecated include with include_tasks --- molecule/aws-ec2/verify.yml | 4 ++-- molecule/default/verify.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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/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" From 98a6c5cdd0f0c3a28b701d2ba92280433644ca50 Mon Sep 17 00:00:00 2001 From: koralowiec Date: Mon, 5 Feb 2024 09:54:53 +0100 Subject: [PATCH 5/5] chore: ignore role-name[path] in test playbook --- .ansible-lint-ignore | 1 + molecule/default/converge.yml | 5 ++++- tests/test.yml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 .ansible-lint-ignore 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/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/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"