├── roles ├── caffe │ ├── meta │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── cudnn │ ├── meta │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── tensorlayer │ ├── meta │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── tensorflow │ ├── meta │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── common │ ├── tasks │ │ ├── chromium.yml │ │ ├── motd.yml │ │ ├── python3.yml │ │ ├── main.yml │ │ └── docker.yml │ └── files │ │ └── 11-help-text ├── youcompleteme │ ├── files │ │ └── vimrc │ └── tasks │ │ └── main.yml └── cuda │ └── tasks │ └── main.yml ├── caffe.yml ├── common.yml ├── all.yml ├── cuda.yml ├── deep-learning.yml └── README.md /roles/caffe/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: 3 | - cudnn 4 | -------------------------------------------------------------------------------- /roles/cudnn/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: 3 | - cuda 4 | -------------------------------------------------------------------------------- /roles/tensorlayer/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: 3 | - tensorflow 4 | -------------------------------------------------------------------------------- /roles/tensorflow/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: 3 | - cuda 4 | - cudnn 5 | -------------------------------------------------------------------------------- /roles/common/tasks/chromium.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - apt: name=chromium-browser state=latest 3 | 4 | -------------------------------------------------------------------------------- /roles/tensorlayer/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - apt: name=python3-tk state=latest 3 | - pip: name=tensorlayer state=latest executable=pip3 4 | 5 | -------------------------------------------------------------------------------- /caffe.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install Caffe 3 | hosts: all 4 | connection: local 5 | gather_facts: no 6 | become: yes 7 | roles: 8 | - caffe 9 | -------------------------------------------------------------------------------- /roles/common/tasks/motd.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Add SSH login welcome message 3 | copy: src=11-help-text dest=/etc/update-motd.d/11-help-text mode="u=rwx,g=rx,o=x" 4 | 5 | -------------------------------------------------------------------------------- /roles/common/files/11-help-text: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | printf "\n" 3 | printf " To install a package please make a pull request to https://github.com/soulmachine/ubuntu-provision\n" 4 | -------------------------------------------------------------------------------- /common.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install common packages 3 | hosts: all 4 | connection: local 5 | gather_facts: no 6 | become: yes 7 | roles: 8 | - common 9 | - cuda 10 | 11 | -------------------------------------------------------------------------------- /all.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install All 3 | hosts: all 4 | connection: local 5 | gather_facts: no 6 | become: yes 7 | roles: 8 | - common 9 | - youcompleteme 10 | - caffe 11 | -------------------------------------------------------------------------------- /cuda.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install Nvidia driver, CUDA and cuDNN 3 | hosts: all 4 | connection: local 5 | gather_facts: no 6 | become: yes 7 | roles: 8 | - cuda 9 | - cudnn 10 | -------------------------------------------------------------------------------- /roles/tensorflow/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Reference: 3 | # https://www.tensorflow.org/install/install_linux 4 | 5 | - apt: name=libcupti-dev state=latest 6 | - pip: name=tensorflow-gpu state=latest executable=pip3 7 | 8 | -------------------------------------------------------------------------------- /deep-learning.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install All Deep Learning Frameworks 3 | hosts: all 4 | connection: local 5 | gather_facts: no 6 | become: yes 7 | roles: 8 | - cuda 9 | - cudnn 10 | - tensorflow 11 | - tensorlayer 12 | -------------------------------------------------------------------------------- /roles/youcompleteme/files/vimrc: -------------------------------------------------------------------------------- 1 | set nocompatible 2 | filetype off 3 | 4 | set rtp+=/usr/share/vim/bundle/Vundle.vim 5 | call vundle#begin('/usr/share/vim/bundle') 6 | 7 | Plugin 'VundleVim/Vundle.vim' 8 | Plugin 'Valloric/YouCompleteMe' 9 | 10 | call vundle#end() 11 | filetype plugin indent on 12 | -------------------------------------------------------------------------------- /roles/common/tasks/python3.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - apt: name={{item}} state=latest 3 | with_items: 4 | - python3 5 | - python3-dev 6 | - libssl-dev 7 | - libffi-dev 8 | - python3-pip 9 | 10 | - pip: name=pip state=latest executable=pip3 11 | - pip: name={{item}} state=latest executable=pip3 12 | with_items: 13 | - setuptools 14 | - wheel 15 | 16 | -------------------------------------------------------------------------------- /roles/cudnn/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Reference: 3 | # https://github.com/NVIDIA/nvidia-docker/blob/master/ubuntu-16.04/cuda/8.0/runtime/cudnn5/Dockerfile 4 | 5 | - name: Check whether cuDNN exists or not 6 | stat: path=/usr/local/cuda/include/cudnn.h 7 | register: cudnn_header 8 | 9 | - name: Download cuDNN 10 | get_url: 11 | url: http://developer.download.nvidia.com/compute/redist/cudnn/v6.0/cudnn-8.0-linux-x64-v6.0.tgz 12 | dest: /tmp/cudnn-8.0-linux-x64-v6.0-tgz 13 | checksum: sha256:36e7cd54d9f4cd448c302a40d2ed530a643e3ae32797a67739448ebe7c9f0620 14 | when: not cudnn_header.stat.exists 15 | 16 | - unarchive: creates=/usr/local/cuda/include/cudnn.h src=/tmp/cudnn-8.0-linux-x64-v6.0-tgz dest=/usr/local owner=root group=root mode=0644 17 | - file: path=/tmp/cudnn-8.0-linux-x64-v6.0-tgz state=absent 18 | -------------------------------------------------------------------------------- /roles/youcompleteme/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Install dependencies of YouCompleteMe 4 | apt: name={{item}} state=latest 5 | with_items: 6 | - vim 7 | - git 8 | - python-dev 9 | - python3-dev 10 | - build-essential 11 | - cmake 12 | 13 | 14 | # Reference https://github.com/VundleVim/Vundle.vim#quick-start 15 | - git_config: name=http.sslVerify scope=global value=false 16 | - name: Install Vundle 17 | git: repo=https://github.com/VundleVim/Vundle.vim.git dest=/usr/share/vim/bundle/Vundle.vim 18 | - copy: src=vimrc dest=/etc/vim/vimrc.local owner=root group=root mode=0644 19 | - shell: creates=/usr/share/vim/bundle/YouCompleteMe vim +PluginInstall +qall 20 | 21 | 22 | # Reference https://github.com/Valloric/YouCompleteMe#ubuntu-linux-x64 23 | - name: Install YouCompleteMe 24 | shell: creates=/usr/share/vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so /usr/share/vim/bundle/YouCompleteMe/install.py --clang-completer 25 | 26 | -------------------------------------------------------------------------------- /roles/cuda/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Reference: 3 | # https://github.com/NVIDIA/nvidia-docker/blob/master/ubuntu-16.04/cuda/8.0/runtime/Dockerfile 4 | # https://developer.nvidia.com/cuda-downloads 5 | 6 | - name: Import Nvidia GPG public key 7 | apt_key: url=http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub state=present 8 | tags: cuda 9 | 10 | - name: Add the Nvidia repository 11 | apt_repository: repo='deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /' state=present update_cache=yes filename='cuda' 12 | 13 | - name: Install Nvidia drivers 14 | apt: name=cuda-drivers state=latest 15 | 16 | - name: Install CUDA Toolkit 17 | apt: name=cuda state=latest 18 | 19 | - copy: content='export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}\nexport LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}\nexport CUDA_HOME=/usr/local/cuda\n' dest=/etc/profile.d/cuda.sh owner=root group=root mode=0644 20 | 21 | -------------------------------------------------------------------------------- /roles/common/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Install essential packages 4 | apt: name={{item}} state=latest 5 | with_items: 6 | - openssh-server 7 | - vim 8 | - wget 9 | - curl 10 | - git 11 | - python 12 | - tree 13 | - colordiff 14 | - build-essential 15 | - cmake 16 | - apt-transport-https 17 | - ca-certificates 18 | - mdadm 19 | - tmux 20 | 21 | 22 | - name: Configure default locale 23 | apt: name=locales state=latest 24 | - locale_gen: name=en_US.UTF-8 state=present 25 | - shell: /usr/sbin/update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 26 | changed_when: False 27 | - copy: content='export LC_ALL=en_US.UTF-8\nexport LANG=en_US.UTF-8\nexport LANGUAGE=en_US:en\n' dest=/etc/profile.d/utf8_locale.sh owner=root group=root mode=0644 28 | 29 | 30 | - name: Install OpenJDK 8 31 | apt: name=openjdk-8-jdk state=latest 32 | - copy: content='export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\nexport PATH=$PATH:$JAVA_HOME/bin\n' dest=/etc/profile.d/openjdk.sh owner=root group=root mode=0644 33 | 34 | 35 | - include: docker.yml 36 | - include: python3.yml 37 | - include: chromium.yml 38 | - include: motd.yml 39 | 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ubuntu 一键装机 2 | 3 | 基本思路是使用 Ansible 来自动化所有操作。 4 | 5 | ## 1. 前期准备 6 | 7 | 8 | ### 1.1 安装 pip 9 | 10 | Ubuntu 16.04 自带了 Python 2.7 和 Python 3.5,所以不需要安装 Python, 但是默认没有 pip, 所以我们需要安装 pip 。 Ansible 目前只能与 Python 2.7 兼容,所以我们只需要给 Python 2.7 安装 pip,千万不要误安装了 `python3-pip` 11 | 12 | sudo apt-get -qy install python-pip 13 | 14 | 15 | ### 1.2 安装 Ansible 16 | 17 | sudo -H pip install --upgrade pip 18 | sudo apt-get -qy install libssl-dev 19 | sudo -H pip install ansible 20 | 21 | 用 `sudo apt-get install ansible` 也可以安装,但是 apt源里的 ansible 版本一般会比较之后,用 pip 方式安装的版本会新一点。 22 | 23 | 24 | ## 2. 执行 playbook 开始一键装机 25 | 26 | ansible-playbook -i localhost, -vv all.yml 27 | 28 | 29 | 或者只安装深度学习相关的框架, 30 | 31 | ansible-playbook -i localhost, -vv deep-learning.yml 32 | 33 | 34 | 几个 playbook 的用途说明: 35 | 36 | * `all.yml` 用来安装所有 37 | * `deep-learning.yml` 用来安装所有深度学习相关的工具,例如 TensorFlow, Caffe, Torch 等 38 | * `cuda.yml` 用于安装 Nvidia 显卡驱动,CUDA 和 cuDNN 39 | * `tensorflow.yml` 是用来构建TensorFlow开发环境的 40 | * `caffe.yml` 用于安装 Caffe 开发环境 41 | * `torch.yml` 用于安装 Torch 开发环境 42 | * `mxnet.yml` 用于安装 mxnet 开发环境 43 | * `r.yml` 用于安装 R, RStudio 44 | * `spark.yml` 用于安装 local 模式的 Apache Spark 45 | 46 | -------------------------------------------------------------------------------- /roles/common/tasks/docker.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Reference: 3 | # https://docs.docker.com/engine/installation/linux/ubuntulinux/ 4 | # https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04 5 | 6 | - apt: name={{item}} state=latest 7 | with_items: 8 | - apt-transport-https 9 | - ca-certificates 10 | 11 | - apt_key: keyserver=hkp://p80.pool.sks-keyservers.net:80 id=58118E89F3A912897C070ADBF76221572C52609D 12 | 13 | - apt_repository: repo='deb https://apt.dockerproject.org/repo ubuntu-xenial main' state=present update_cache=yes filename='docker' 14 | 15 | - apt: name=lxc-docker state=absent purge=yes 16 | 17 | - shell: apt-cache policy docker-engine 18 | changed_when: False 19 | 20 | - shell: uname -r 21 | ignore_errors: yes 22 | changed_when: False 23 | register: uname_result 24 | 25 | - apt: name={{item}} state=present 26 | with_items: 27 | - linux-image-extra-{{ uname_result.stdout }} 28 | - linux-image-extra-virtual 29 | 30 | - apt: name=docker-engine state=latest 31 | 32 | - service: name=docker state=started enabled=yes 33 | 34 | # Executing the Docker Command Without Sudo 35 | - group: name=docker state=present 36 | - shell: awk -F{{ ":" }} '($3>=1000)&&($1!="nobody"){print $1}' /etc/passwd 37 | ignore_errors: yes 38 | changed_when: False 39 | register: non_system_users 40 | - user: name={{ item }} groups=docker append=yes 41 | with_items: "{{ non_system_users.stdout_lines }}" 42 | -------------------------------------------------------------------------------- /roles/caffe/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Reference: 3 | # http://caffe.berkeleyvision.org/install_apt.html 4 | # https://github.com/IraAI/caffe-gpu-installation/wiki/How-to-install-Caffe-on-Ubuntu-16.04-with-GPU-(Cuda-8,-CuDNN-5.1) 5 | 6 | - name: Check whether Caffe exists or not 7 | stat: path=/usr/local/caffe/bin/caffe.bin 8 | register: caffe 9 | 10 | - name: Install dependencies of Caffe 11 | apt: name={{item}} state=latest 12 | with_items: 13 | - build-essential 14 | - libprotobuf-dev 15 | - libleveldb-dev 16 | - libsnappy-dev 17 | - libopencv-dev 18 | - libhdf5-serial-dev 19 | - protobuf-compiler 20 | - libboost-all-dev 21 | - python-pip 22 | - python-dev 23 | - libgflags-dev 24 | - libgoogle-glog-dev 25 | - liblmdb-dev 26 | 27 | - name: Install OpenBLAS instead of ATLAS for better CPU performance 28 | apt: name=libopenblas-dev state=latest 29 | 30 | - git_config: name=http.sslVerify scope=global value=false 31 | - git: repo=https://github.com/BVLC/caffe.git dest=/tmp/caffe 32 | when: not caffe.stat.exists 33 | - pip: requirements=/tmp/caffe/python/requirements.txt 34 | when: not caffe.stat.exists 35 | - shell: creates=/tmp/caffe/Makefile.config cp /tmp/caffe/Makefile.config.example /tmp/caffe/Makefile.config 36 | when: not caffe.stat.exists 37 | - lineinfile: dest=/tmp/caffe/Makefile.config regexp="^#?\s*USE_CUDNN\s+:=" line="USE_CUDNN := 1" 38 | when: not caffe.stat.exists 39 | - lineinfile: dest=/tmp/caffe/Makefile.config regexp="^#?\s*WITH_PYTHON_LAYER\s+:=" line="WITH_PYTHON_LAYER := 1" 40 | when: not caffe.stat.exists 41 | - lineinfile: dest=/tmp/caffe/Makefile.config regexp="^#?\s*CPU_ONLY\s+:=" line="# CPU_ONLY := 1" 42 | when: not caffe.stat.exists 43 | - lineinfile: dest=/tmp/caffe/Makefile.config regexp="^#?\s*BLAS\s+:=" line="BLAS := open" 44 | when: not caffe.stat.exists 45 | # We use pip to install numpy, which installs numpy to a different place 46 | - lineinfile: dest=/tmp/caffe/Makefile.config regexp="^\s*/usr/lib/python2.7/dist-packages/numpy/core/include" line="\t\t/usr/local/lib/python2.7/dist-packages/numpy/core/include" 47 | when: not caffe.stat.exists 48 | # Append hdf5 header files 49 | - lineinfile: dest=/tmp/caffe/Makefile.config regexp="^#?\s*INCLUDE_DIRS\s+:=" line="INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial" 50 | when: not caffe.stat.exists 51 | # Append hdf5 libraries 52 | - lineinfile: dest=/tmp/caffe/Makefile.config regexp="^#?\s*LIBRARY_DIRS\s+:=" line="LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial" 53 | when: not caffe.stat.exists 54 | 55 | - make: 56 | chdir: /tmp/caffe 57 | target: all 58 | params: 59 | NUM_THREADS: 8 60 | when: not caffe.stat.exists 61 | - make: 62 | chdir: /tmp/caffe 63 | target: pycaffe 64 | params: 65 | NUM_THREADS: 8 66 | when: not caffe.stat.exists 67 | - make: 68 | chdir: /tmp/caffe 69 | target: test 70 | params: 71 | NUM_THREADS: 8 72 | when: not caffe.stat.exists 73 | - make: 74 | chdir: /tmp/caffe 75 | target: distribute 76 | params: 77 | NUM_THREADS: 8 78 | when: not caffe.stat.exists 79 | 80 | - shell: cp -r /tmp/caffe/distribute /usr/local/caffe 81 | when: not caffe.stat.exists 82 | 83 | - file: path=/tmp/caffe state=absent 84 | 85 | - copy: content='export PATH=/usr/local/caffe/bin${PATH:+:${PATH}}\nexport PYTHONPATH=/usr/local/caffe/python${PYTHONPATH:+:${PYTHONPATH}}\nexport LD_LIBRARY_PATH=/usr/local/caffe/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}\n' dest=/etc/profile.d/caffe.sh owner=root group=root mode=0644 86 | 87 | --------------------------------------------------------------------------------