Skip to content

Commit

Permalink
Merge pull request #22 from Appsilon/feat/jupyter-kernel
Browse files Browse the repository at this point in the history
feat: add ability to make Python available as Jupyter Kernel
  • Loading branch information
koralowiec authored Feb 5, 2024
2 parents 36fddc0 + 98a6c5c commit 2e1a809
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions .ansible-lint-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/test.yml role-name[path]
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
python_versions:
- 3.10.6
- 3.9.13
python_jupyter_kernel: true
4 changes: 2 additions & 2 deletions molecule/aws-ec2/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 4 additions & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}/../../"
4 changes: 2 additions & 2 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
27 changes: 27 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 2e1a809

Please sign in to comment.