Skip to content

Commit c9b0856

Browse files
committed
feat: add jupyter installation
1 parent bb5c937 commit c9b0856

File tree

9 files changed

+106
-0
lines changed

9 files changed

+106
-0
lines changed

.ansible-lint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exclude_paths:
66
- .cache/
77
- molecule/default
88
- molecule/aws-ec2
9+
- molecule/jupyter-system
910
offline: false
1011
use_default_rules: true
1112
parseable: true

defaults/main.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,16 @@ python_versions:
44
- 3.10.6
55
- 3.9.13
66
python_jupyter_kernel: true
7+
python_jupyter_install: true
8+
# Possible values: system, virtualenv
9+
python_jupyter_install_method: virtualenv
10+
# Python version to use for Jupyter installation
11+
python_jupyter_python_version: "{{ python_versions[0] }}"
12+
python_jupyter_virtualenv_path: /opt/jupyter
13+
python_jupyter_packages:
14+
- jupyterlab
15+
- notebook>=6.0.0,<7.0.0
16+
python_jupyter_workbench: true
17+
python_jupyter_workbench_packages:
18+
- rsp_jupyter
19+
- workbench_jupyterlab==1.1.315

molecule/jupyter-system/converge.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
become: true
5+
pre_tasks:
6+
- name: Include main vars
7+
include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml"
8+
- name: Include jupyter-system vars
9+
include_vars: "{{ playbook_dir }}/../../tests/vars/jupyter-system.yml"
10+
roles:
11+
- "{{ playbook_dir }}/../../"

molecule/jupyter-system/molecule.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: docker
6+
platforms:
7+
- name: instance-jupyter-system
8+
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest"
9+
command: ${MOLECULE_DOCKER_COMMAND:-""}
10+
volumes:
11+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
12+
privileged: true
13+
cgroupns_mode: host
14+
pre_build_image: true
15+
platform: linux/amd64
16+
provisioner:
17+
name: ansible
18+
playbooks:
19+
prepare: prepare.yml
20+
converge: converge.yml
21+
verify: verify.yml

molecule/jupyter-system/prepare.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: Prepare
3+
hosts: all
4+
become: true
5+
tasks: []

molecule/jupyter-system/verify.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
become: true
5+
pre_tasks:
6+
- name: Include vars
7+
ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml"
8+
tasks:
9+
- name: Include tasks
10+
ansible.builtin.include_tasks: "{{ playbook_dir }}/../../tests/tasks/post.yml"

tasks/install-jupyter.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
- name: Combine jupyter packages
3+
ansible.builtin.set_fact:
4+
python_jupyter_packages: "{{ python_jupyter_packages + python_jupyter_workbench_packages }}"
5+
when: python_jupyter_workbench
6+
7+
- name: Install jupyter packages (virtualenv method)
8+
ansible.builtin.pip:
9+
name: "{{ python_jupyter_packages }}"
10+
virtualenv_command: "/opt/python/{{ python_jupyter_python_version }}/bin/python -m venv"
11+
virtualenv: "{{ python_jupyter_virtualenv_path }}"
12+
when: python_jupyter_install_method == "virtualenv"
13+
14+
- name: Install jupyter packages (system method)
15+
ansible.builtin.pip:
16+
name: "{{ python_jupyter_packages }}"
17+
executable: pip3
18+
when: python_jupyter_install_method == "system"
19+
20+
- name: Set path to jupyter-nbextension
21+
ansible.builtin.set_fact:
22+
jupyter_nbextension_path: "{{ (python_jupyter_install_method == 'virtualenv') | ternary(python_jupyter_virtualenv_path + '/bin/', '') }}jupyter-nbextension"
23+
jupyter_etc_nbconfig: "{{ (python_jupyter_install_method == 'virtualenv') | ternary('/opt/jupyter', '/usr') }}/etc/jupyter/nbconfig"
24+
25+
- name: Install Workbench's jupyter plugin
26+
ansible.builtin.command: |
27+
{{ jupyter_nbextension_path }} install --sys-prefix --py rsp_jupyter
28+
register: command_result
29+
# jupyter-nbextension returns the needed information in stderr
30+
changed_when: "'Copying:' in command_result.stderr"
31+
when: python_jupyter_workbench
32+
33+
- name: Enable Workbench's jupyter plugin
34+
ansible.builtin.shell: |
35+
grep 'rsp_jupyter/index' {{ jupyter_etc_nbconfig }}/notebook.json || echo "File doesn't exist yet"
36+
{{ jupyter_nbextension_path }} enable --sys-prefix --py rsp_jupyter
37+
register: command_result
38+
changed_when: "'\"rsp_jupyter/index\": true' not in command_result.stdout"
39+
when: python_jupyter_workbench

tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@
5757
index_var: index
5858
register: command_result
5959
changed_when: kernel_json.results[index].stat.exists == false
60+
61+
- name: Include tasks | Jupyter installation
62+
ansible.builtin.include_tasks: './install-jupyter.yml'

tests/vars/jupyter-system.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# vars file
2+
---
3+
python_jupyter_install_method: system

0 commit comments

Comments
 (0)