Skip to content

Instantly share code, notes, and snippets.

@tbuchi888
Last active August 25, 2018 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tbuchi888/240df64592302bbee9d823c1c36e0692 to your computer and use it in GitHub Desktop.
Save tbuchi888/240df64592302bbee9d823c1c36e0692 to your computer and use it in GitHub Desktop.
Ansible run on Jupyter notebook : CentOS6で`実行可能な手順書`の環境を構築する( playbookやVagrantfileあり) ref: https://qiita.com/tbuchi888/items/4f4ed9192e2027759795
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
# Please replace it with a BOX name of CentOS6 for one's own 32bit when your host is 32bit machine.
config.vm.box = "geerlingguy/centos6"
# Add forwarded port to use on Jupyter notebook
config.vm.network "forwarded_port", guest: 8888, host: 8888, host_ip: "127.0.0.1",
auto_correct: true
# Add ansible provisioner
config.vm.provision "ansible" do |ansible|
ansible.playbook = "site.yml"
end
end
$ansible --version
ansible 2.1.0 (devel c600ab81ee) last updated 2016/04/20 11:11:25 (GMT +900)
lib/ansible/modules/core: (detached HEAD 98322a777f) last updated 2016/04/20 11:11:54 (GMT +900)
lib/ansible/modules/extras: (detached HEAD 1aecfc1e19) last updated 2016/04/20 11:11:55 (GMT +900)
config file =
configured module search path = Default w/o overrides
#!/bin/bash
trap 'pkill -f jupyter-notebook; sleep 3; exit 0' EXIT
if [ "${PASSWORD-undef}" = "undef" ]; then
export PASSWORD='{{jupyter_password}}'
fi
if ! grep -qE '^c.NotebookApp.password =' $HOME/.jupyter/jupyter_notebook_config.py; then
HASH=$(python -c "from IPython.lib import passwd; print(passwd('${PASSWORD}'))")
echo "c.NotebookApp.password = u'${HASH}'" >>$HOME/.jupyter/jupyter_notebook_config.py
fi
unset PASSWORD
unset HASH
mkdir -p $HOME/notebook
cd $HOME/notebook
# Comment out the following line.
#ipython -c '%matplotlib' # build font cache for matplotlib
jupyter notebook
---
# Setting the destination inventory host
- hosts: all
become: yes
become_method: sudo
become_user: root
# Don't gather hosts facts for performance
gather_facts: no
vars:
jupyter_password: pass
# Setting the task
tasks:
- name: yum install with_items
yum:
name: '{{ item.name }}'
state: latest
with_items:
- name: '*'
- name: "@Development Tools"
- name: epel-release
- name: python-devel
- name: python-pip
- name: lapack-devel
- name: freetype-devel
- name: libpng-devel
- name: libjpeg-turbo-devel
- name: ansible
- name: copy init.sh for jupyter notebook
template:
src: init.sh.j2
dest: /usr/local/bin/init.sh
mode: u+x
- name: command by shell module with_items
shell: '{{item.cmd}}'
register: RESULT
with_items:
- cmd: source ~/.bash_profile; pip install jupyter
- cmd: source ~/.bash_profile; jupyter notebook --generate-config
- cmd: source ~/.bash_profile; echo "c.NotebookApp.ip = '*'" >>/root/.jupyter/jupyter_notebook_config.py && echo "c.NotebookApp.open_browser = False" >>/root/.jupyter/jupyter_notebook_config.py
- cmd: source ~/.bash_profile; nohup /usr/local/bin/init.sh &
- cmd: lokkit -p 8888:tcp
- debug: var=RESULT.results
---
- hosts: all
gather_facts: no
become: yes
vars:
python_ver: 2.7.8
tasks:
- name: which pyenv
shell: source ~/.bash_profile; which pyenv
register: pyenv_install
failed_when: pyenv_install.rc == 0
- debug: var=pyenv_install
- block:
- debug: msg="---------- block start ----------"
- name: yum install with_items
yum:
name: '{{ item.name }}'
state: latest
register: RESULT
with_items:
- name: gcc
- name: gcc-c++
- name: make
- name: git
- name: openssl-devel
- name: bzip2-devel
- name: zlib-devel
- name: readline-devel
- name: sqlite-devel
- name: bzip2
- name: sqlite
- name: patch
- name: results
debug: var=RESULT.results
- name: git clone pyenv , pyenv-virtualenv
git:
repo: '{{ item.repo }}'
dest: '{{ item.dest }}'
register: RESULT
with_items:
- repo: git://github.com/yyuu/pyenv.git
dest: ~/.pyenv
- repo: git://github.com/yyuu/pyenv-virtualenv.git
dest: ~/.pyenv/plugins/pyenv-virtualenv
- name: results
debug: var=RESULT.results
- name: "install pyenv and python ver.{{ python_ver }}"
shell: '{{ item.cmd }}'
register: RESULT
with_items:
- cmd: echo 'export PYENV_ROOT="${HOME}/.pyenv"' >> ~/.bash_profile
- cmd: echo 'if [ -d "${PYENV_ROOT}" ]; then' >> ~/.bash_profile
- cmd: echo ' export PATH=${PYENV_ROOT}/bin:$PATH' >> ~/.bash_profile
- cmd: echo ' eval "$(pyenv init -)"' >> ~/.bash_profile
- cmd: echo 'fi' >> ~/.bash_profile
- cmd: source ~/.bash_profile; pyenv -v
- cmd: source ~/.bash_profile; python -V
- cmd: source ~/.bash_profile; pyenv install '{{ python_ver }}'
- cmd: source ~/.bash_profile; pyenv global '{{ python_ver }}'
- cmd: source ~/.bash_profile; python -V
- name: results
debug: var=RESULT.results
- debug: msg="---------- block end ----------"
when: pyenv_install.rc == 1
---
- include: install_pyenv_without_proxy.yml
- include: install_jupyter_ansible_without_proxy.yml
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
# Please replace it with a BOX name of CentOS6 for one's own 32bit when your host is 32bit machine.
config.vm.box = "geerlingguy/centos6"
# Add forwarded port to use on Jupyter notebook
config.vm.network "forwarded_port", guest: 8888, host: 8888, host_ip: "127.0.0.1",
auto_correct: true
# Add ansible provisioner
config.vm.provision "ansible" do |ansible|
ansible.playbook = "site.yml"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment