-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.sh
96 lines (89 loc) · 2.7 KB
/
bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
# Ensure running as regular user
if [ $(id -u) -eq 0 ] ; then
echo "Please run as a regular user"
exit 1
fi
# Install newer version of Ansible
sudo apt-get -y install software-properties-common
sudo apt-add-repository -y ppa:ansible/ansible
sudo apt-get update
sudo apt-get -y install ansible
# Install Docker if needed
# Add docker role from Ansible Galaxy
ansible-galaxy install angstwad.docker_ubuntu --roles-path=/tmp/roles
tags="--skip-tags docker"
type docker >/dev/null 2>&1
if [ $? -eq 1 ] ; then
tags=
fi
# Write playbook
f=$(mktemp)
cat <<EOF > $f
- hosts: all
become: true
become_method: sudo
vars:
docker_pkg_name: "docker-ce=17.12*"
daemon_json:
default-runtime: "nvidia"
runtimes:
nvidia:
path: "/usr/bin/nvidia-container-runtime"
runtimeArgs: []
roles:
- { role: angstwad.docker_ubuntu, tags: docker }
tasks:
- name: docker | add user to docker group
user: name=$USER groups=docker append=yes
- name: cuda | apt key
apt_key:
url: http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
state: present
- name: cuda | repo
apt: deb=http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
- name: cuda | install prereqs
apt: name={{ item }} state=latest update_cache=yes cache_valid_time=600
with_items:
- build-essential
- linux-source
- linux-generic
- dkms
- name: cuda | install cuda driver
apt: name={{ item }} state=latest update_cache=yes
with_items:
- cuda-drivers
- name: nvidia-docker | apt key
apt_key:
url: https://nvidia.github.io/nvidia-docker/gpgkey
state: present
- name: nvidia-docker | apt repo
apt_repository:
repo: "{{ item }}"
state: present
filename: 'nvidia-docker'
update_cache: yes
with_items:
- "deb https://nvidia.github.io/libnvidia-container/ubuntu16.04/amd64 /"
- "deb https://nvidia.github.io/nvidia-container-runtime/ubuntu16.04/amd64 /"
- "deb https://nvidia.github.io/nvidia-docker/ubuntu16.04/amd64 /"
- name: nvidia-docker | install
apt:
name: nvidia-docker2
state: latest
- name: set docker default runtime
copy:
content: "{{ daemon_json | to_nice_json }}"
dest: /etc/docker/daemon.json
owner: root
group: root
mode: 0644
- name: docker | restart service
service: name=docker state=restarted enabled=yes
EOF
# Execute playbook
ansible-playbook -i "localhost," -c local ${tags} $f
# cleanup
rm -f $f
rm -rf /tmp/roles
exit