Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to make Python available as Jupyter Kernel #22

Merged
merged 5 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,6 +1,6 @@
# test file
---
- name: Include vars and tasks

Check warning on line 3 in tests/test.yml

View workflow job for this annotation

GitHub Actions / Lint

role-name[path]

Avoid using paths when importing roles. ({{ playbook_dir }}/..)
hosts: localhost
connection: local
become: true
Expand All @@ -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"
Loading