Skip to content

Commit 02a3812

Browse files
authored
Merge pull request #25 from Appsilon/feat/jupyter-installation
[WIP] feat: add Jupyter installation
2 parents f1596be + 416a6ed commit 02a3812

File tree

13 files changed

+139
-23
lines changed

13 files changed

+139
-23
lines changed

.ansible-lint

+1
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

.github/workflows/ci.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ jobs:
4444
include:
4545
- distro: ubuntu2004
4646
ansible-version: '>=2.11.5'
47+
scenario: 'default'
4748
- distro: ubuntu2204
4849
ansible-version: '>=2.11.5'
50+
scenario: 'default'
51+
- distro: ubuntu2204
52+
ansible-version: '>=2.11.5'
53+
scenario: 'jupyter-system'
4954
- distro: rockylinux8
5055
ansible-version: '>=2.11.5'
56+
scenario: 'default'
5157

5258
steps:
5359
- name: Check out the codebase
@@ -65,7 +71,7 @@ jobs:
6571

6672
- name: Run Molecule tests
6773
run: |
68-
molecule test
74+
molecule test -s "${{ matrix.scenario }}"
6975
env:
7076
ANSIBLE_FORCE_COLOR: '1'
7177
ANSIBLE_VERBOSITY: '2'

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
# Ansible Python Install
22

3-
Install Python on Ubuntu and RedHat based systems with Posit's pre-compiled binaries ([docs](https://docs.posit.co/resources/install-python/))
3+
Install Python (with Jupyter) on Ubuntu and RedHat based systems with Posit's pre-compiled binaries ([docs](https://docs.posit.co/resources/install-python/))
44

55
[![CI](https://github.com/Appsilon/ansible-python-install/workflows/CI/badge.svg)](https://github.com/Appsilon/ansible-python-install/actions/workflows/ci.yml)
66
[![Ansible Galaxy](https://img.shields.io/badge/ansible--galaxy-appsilon.python_install-blue.svg)](https://galaxy.ansible.com/appsilon/python_install)
77

88
## Requirements
99

10-
None.
10+
If you want to install Workbench's plugins, then the Python used for Jupyter installation needs to be >= 3.7
1111

1212
## Role Variables
1313

14-
| Variable | Required | Default | Choices | Comments |
15-
|-----------------|----------|------------------|-----------------------------------|---------------------------------------|
16-
| 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 |
14+
| Variable | Default | Choices | Comments |
15+
|-----------------|------------------|-----------------------------------|---------------------------------------|
16+
| python_versions | [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 | true | Boolean: true, false | Makes Python available as a Jupyter Kernel |
18+
| python_jupyter_install | true | Boolean: true, false | Whether to install Jupyter |
19+
| python_jupyter_install_method | virtualenv | String: virtualenv, system | Method of Jupyter installation |
20+
| python_jupyter_python_version | `"{{ python_versions[0] }}"` | One of the versions passed in python_versions | Used only for virtualenv method |
21+
| python_jupyter_workbench | true | Boolean: true, false | Whether to install Workbench's plugins for Jupyter |
1822

1923
## Dependencies
2024

defaults/main.yml

+14
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,17 @@ 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+
# when using virtualenv method
12+
python_jupyter_python_version: "{{ python_versions[0] }}"
13+
python_jupyter_virtualenv_path: /opt/jupyter
14+
python_jupyter_packages:
15+
- jupyterlab
16+
- notebook>=6.0.0,<7.0.0
17+
python_jupyter_workbench: true
18+
python_jupyter_workbench_packages:
19+
- rsp_jupyter
20+
- workbench_jupyterlab==1.1.315

molecule/jupyter-system/converge.yml

+11
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

+21
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

+5
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

+10
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/debian/main.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: Install additional python versions | Install system dependencies
2+
- name: Install Python | Install system dependencies
33
ansible.builtin.apt:
44
pkg: "{{ python_system_dependecies }}"
55
state: "{{ apt_install_state | default('latest') }}"
@@ -8,15 +8,15 @@
88
tags:
99
- python-install-system-dependecies
1010

11-
- name: Install additional python versions | Set release version
11+
- name: Install Python | Set release version
1212
ansible.builtin.set_fact:
1313
ubuntu_release: "{{ ansible_facts['distribution_version'] | replace('.', '') }}"
1414
when: ansible_facts['distribution'] == "Ubuntu"
1515
tags:
1616
- python-install-set-facts
1717
- python-install-setup-versions
1818

19-
- name: Install additional python versions | Download deb package
19+
- name: Install Python | Download deb package
2020
ansible.builtin.get_url:
2121
url: "https://cdn.rstudio.com/python/ubuntu-{{ ubuntu_release }}/pkgs/python-{{ item }}_1_amd64.deb"
2222
dest: "/tmp/Python-{{ item }}.deb"
@@ -26,7 +26,7 @@
2626
- python-install-download-archives
2727
- python-install-setup-versions
2828

29-
- name: Install additional python versions | Install deb package
29+
- name: Install Python | Install deb package
3030
ansible.builtin.apt:
3131
deb: "/tmp/Python-{{ item }}.deb"
3232
loop: "{{ python_versions }}"

tasks/install-jupyter.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
- name: Install Python | 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 Python | 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 Python | 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: Install Python | 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 Python | 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: Install Python | 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

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# tasks file
22
---
3-
- name: Include variables
3+
- name: Install Python | Include variables
44
ansible.builtin.include_vars: "{{ item }}"
55
with_first_found:
66
- "_{{ ansible_distribution_release }}.yml"
@@ -10,18 +10,18 @@
1010
tags:
1111
- configuration
1212

13-
- name: Create download directory
13+
- name: Install Python | Create download directory
1414
ansible.builtin.file:
1515
path: "{{ downloads_path }}"
1616
state: directory
1717
owner: root
1818
group: root
1919
mode: 0755
2020

21-
- name: Include tasks
21+
- name: Install Python | Include installation tasks
2222
ansible.builtin.include_tasks: '{{ ansible_os_family | lower }}/main.yml'
2323

24-
- name: Install python | Upgrade tools
24+
- name: Install Python | Upgrade tools
2525
ansible.builtin.command: >
2626
/opt/python/{{ item }}/bin/pip install --upgrade \
2727
pip setuptools wheel
@@ -31,24 +31,24 @@
3131
tags:
3232
- python-install-upgrade-tools
3333

34-
- name: Install python | Make available as a Jupyter Kernel
34+
- name: Install Python | Make available as a Jupyter Kernel
3535
when: python_jupyter_kernel
3636
tags:
3737
- python-install-jupyter-kernel
3838
block:
39-
- name: Install python | Install ipykernel
39+
- name: Install Python | Install ipykernel
4040
ansible.builtin.pip:
4141
executable: "/opt/python/{{ item }}/bin/pip"
4242
name: ipykernel
4343
loop: "{{ python_versions }}"
4444

45-
- name: Install python | Check if kernel.json exists
45+
- name: Install Python | Check if kernel.json exists
4646
ansible.builtin.stat:
4747
path: "/usr/local/share/jupyter/kernels/py{{ item }}/kernel.json"
4848
loop: "{{ python_versions }}"
4949
register: kernel_json
5050

51-
- name: Install python | Make available as a Jupyter Kernel
51+
- name: Install Python | Run ipykernel install
5252
ansible.builtin.command: >
5353
/opt/python/{{ item }}/bin/python -m ipykernel install \
5454
--name py{{ item }} --display-name "Python {{ item }}"
@@ -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: Install Python | Include Jupyter installation tasks
62+
ansible.builtin.include_tasks: './install-jupyter.yml'

tasks/redhat/main.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
2-
3-
- name: Install python | Install dependecies
2+
- name: Install Python | Install dependecies
43
ansible.builtin.yum:
54
name: "{{ system_dependecies }}"
65

7-
- name: Install python | Download rpm package
6+
- name: Install Python | Download rpm package
87
ansible.builtin.get_url:
98
url: "{{ python_download_url }}/python-{{ item }}-1-1.x86_64.rpm"
109
dest: "{{ downloads_path }}/python-{{ item }}-1-1.x86_64.rpm"
@@ -14,7 +13,7 @@
1413
- python-install-download-archives
1514
- python-install-setup-versions
1615

17-
- name: Install python | Install rpm package
16+
- name: Install Python | Install rpm package
1817
ansible.builtin.yum:
1918
name: "{{ downloads_path }}/python-{{ item }}-1-1.x86_64.rpm"
2019
disable_gpg_check: true

tests/vars/jupyter-system.yml

+3
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)