softasap.sa-jupyterhub
sa-jupyterhub
将使用 jupyterhub 的用户添加到 jupyter 组中
sudo usermod -a -G jupyter 用户名
# 例如:
sudo usermod -a -G jupyter vagrant
sudo usermod -a -G jupyter ubuntu
如果用户不被允许使用 Jupyterhub,系统将无法为该用户启动会话,尽管错误信息可能会误导,例如 “Anaconda Error in Authenticator.pre_spawn_start: ValueError substring not found”。
用法示例:
简单示例
     - {
         role: "sa-jupyterhub"
       }
高级示例
     - {
         role: "sa-jupyterhub",
         option_install_python2: True,
         option_install_python3: True,
         option_install_anaconda: True,
         option_install_git: True,
         jupyterhub_python: "anaconda",  # python3 / anaconda
         option_install_nodejs_legacy: True,
         jupyterhub_properties:
           - {regexp: "^c.Authenticator.admin_users*", line: "c.Authenticator.admin_users = {'jupyter'}"}
           - {regexp: "^c.LocalAuthenticator.create_system_users*", line: "c.LocalAuthenticator.create_system_users = True"}
           - {regexp: "^c.JupyterHub.confirm_no_ssl*", line: "c.JupyterHub.confirm_no_ssl = True"}
         jupyterhub_ip: "{{ansible_default_ipv4.address}}",
         # ANACONDA
         anaconda_version: '5.1.0',
         anaconda_python: 3, # 2|3
         option_anaconda_addtoprofile: False,
         option_anaconda_update_packages: True,
         anaconda_base_dir: /usr/local,
         anaconda_additional_packages: [],
         # /ANACONDA
         # PYTHON 3
         python_version: "3.6.4"
         # /PYTHON 3
       }
致谢:
如果您选择使用 Python3 安装 Anaconda,请使用第三方模块来管理那里的软件包:
Anaconda 的 Python 模块:https://github.com/UDST/ansible-conda,许可证在 library/License.txt 中。
安装自定义内核
- 以 jupyter 用户身份登录
$ whoami
jupyter
- 列出可用的内核
jupyter kernelspec list
3.1 使用 conda 创建新内核
注意:您可能需要通过调用以下命令为使用 conda 准备您的 shell
conda init <SHELL_NAME>
/usr/local/anaconda/bin/conda search "^python$"
...
python                         3.8.2      h191fe78_0  pkgs/main
python                         3.8.2      hcf32534_0  pkgs/main
选择 Python 版本并创建虚拟环境
/usr/local/anaconda/bin/conda create -n Anaconda3.6 python=3.6 anaconda
一旦创建,激活之前创建的环境
conda activate Anaconda3.6
确保环境已被激活并安装 ipykernel
(Anaconda3.6) jupyter@bionic:~$ pip install ipykernel
为您的 jupyter notebooks 注册 Anaconda3.6:
python -m ipykernel install --user --name Anaconda3.6 --display-name  "Python 3.6 - anaconda venv"
Installed kernelspec Anaconda3.6 in /home/jupyter/.local/share/jupyter/kernels/anaconda3.6
完成!
jupyter kernelspec list
可用内核:
  anaconda3.6    /home/jupyter/.local/share/jupyter/kernels/anaconda3.6
  python3        /usr/local/share/jupyter/kernels/python3
请注意,内核注册只不过是一个 JSON 文件 cat /home/vagrant/.local/share/jupyter/kernels/anaconda3.6/kernel.json
{
 "argv": [
  "/home/vagrant/.conda/envs/Anaconda3.6/bin/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3.6 - anaconda venv",
 "language": "python"
}
您可以为自己的用户安装内核,也可以为所有用户安装,此时定义应放在 /usr/local/share/jupyter/kernels/ 并且您应该进行适当的权限设置(即,为 jupyter 组设置写入权限)。
3.2 安装 ansible 内核
pip install ansible-kernel
python -m ansible_kernel.install
或者
pip install ansible-kernel
python -m ansible_kernel.install --sys-prefix
与 ansible galaxy 工作流的用法
如果您使用以下命令安装了 sa-jupyterhub 角色:
   ansible-galaxy install softasap.sa-jupyterhub
该角色将可在文件夹 library/softasap.sa-jupyterhub 中找到。
请根据实际情况调整路径。
     - {
         role: "softasap.sa-jupyterhub"
       }
版权和许可证
代码在 BSD 3 条款 和 MIT 许可证 下双重授权。请选择适合您的许可证。
联系我们:
在 FB 订阅角色更新。
加入 Gitter 讨论频道。
在 http://www.softasap.com/roles/registry_generated.html 发现其他角色。
