Skip to content

Commit 2e1a809

Browse files
authored
Merge pull request #22 from Appsilon/feat/jupyter-kernel
feat: add ability to make Python available as Jupyter Kernel
2 parents 36fddc0 + 98a6c5c commit 2e1a809

File tree

9 files changed

+40
-7
lines changed

9 files changed

+40
-7
lines changed

.ansible-lint-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/test.yml role-name[path]

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ repos:
3131
- id: shell-lint
3232

3333
- repo: https://github.com/ansible-community/ansible-lint
34-
rev: v6.0.0
34+
rev: v6.22.2
3535
hooks:
3636
- id: ansible-lint
3737

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ None.
1414
| Variable | Required | Default | Choices | Comments |
1515
|-----------------|----------|------------------|-----------------------------------|---------------------------------------|
1616
| python_versions | yes | [3.10.6, 3.9.13] | Array with Python versions >= 3.7 | Version have to be specified as 3.x.y |
17+
| python_jupyter_kernel | no | true | Boolean: true, false | Makes Python available as a Jupyter Kernel |
1718

1819
## Dependencies
1920

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
python_versions:
44
- 3.10.6
55
- 3.9.13
6+
python_jupyter_kernel: true

molecule/aws-ec2/verify.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
gather_facts: false
77
pre_tasks:
88
- name: Include vars
9-
include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml"
9+
ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml"
1010
- name: Include tasks
11-
include: "{{ playbook_dir }}/../../tests/tasks/post.yml"
11+
ansible.builtin.include_tasks: "{{ playbook_dir }}/../../tests/tasks/post.yml"

molecule/default/converge.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
pre_tasks:
66
- name: Include vars
77
include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml"
8+
- name: debug
9+
debug:
10+
var: playbook_dir
811
roles:
9-
- ../../../
12+
- "{{ playbook_dir }}/../../"

molecule/default/verify.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
become: true
55
pre_tasks:
66
- name: Include vars
7-
include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml"
7+
ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml"
88
tasks:
99
- name: Include tasks
10-
include: "{{ playbook_dir }}/../../tests/tasks/post.yml"
10+
ansible.builtin.include_tasks: "{{ playbook_dir }}/../../tests/tasks/post.yml"

tasks/main.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,30 @@
3030
changed_when: "'Successfully installed' in command_result.stdout"
3131
tags:
3232
- python-install-upgrade-tools
33+
34+
- name: Install python | Make available as a Jupyter Kernel
35+
when: python_jupyter_kernel
36+
tags:
37+
- python-install-jupyter-kernel
38+
block:
39+
- name: Install python | Install ipykernel
40+
ansible.builtin.pip:
41+
executable: "/opt/python/{{ item }}/bin/pip"
42+
name: ipykernel
43+
loop: "{{ python_versions }}"
44+
45+
- name: Install python | Check if kernel.json exists
46+
ansible.builtin.stat:
47+
path: "/usr/local/share/jupyter/kernels/py{{ item }}/kernel.json"
48+
loop: "{{ python_versions }}"
49+
register: kernel_json
50+
51+
- name: Install python | Make available as a Jupyter Kernel
52+
ansible.builtin.command: >
53+
/opt/python/{{ item }}/bin/python -m ipykernel install \
54+
--name py{{ item }} --display-name "Python {{ item }}"
55+
loop: "{{ python_versions }}"
56+
loop_control:
57+
index_var: index
58+
register: command_result
59+
changed_when: kernel_json.results[index].stat.exists == false

tests/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- name: Include vars
99
ansible.builtin.include_vars: "{{ playbook_dir }}/vars/main.yml"
1010
roles:
11-
- ../../
11+
- "{{ playbook_dir }}/.."
1212
post_tasks:
1313
- name: Include tasks
1414
ansible.builtin.include_tasks: "{{ playbook_dir }}/tasks/post.yml"

0 commit comments

Comments
 (0)