Skip to content

Commit

Permalink
cbox implemet part
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDoobPG authored and MrDoobPG committed Aug 23, 2019
1 parent cda4bf7 commit 23e21b8
Show file tree
Hide file tree
Showing 22 changed files with 873 additions and 1 deletion.
16 changes: 16 additions & 0 deletions menu/functions/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pginstall() {
core mergerinstall
core dockerinstall
core docstart
core kernel
core cloudflare

touch /var/plexguide/install.roles
rolenumber=3
Expand Down Expand Up @@ -105,6 +107,8 @@ pginstall() {
core mountcheck
emergency
pgdeploy
core kernel
core cloudflare
}

core() {
Expand Down Expand Up @@ -155,6 +159,18 @@ docstart() {
ansible-playbook /opt/plexguide/menu/pg.yml --tags docstart
}

kernel () {
ansible-playbook /opt/plexguide/menu/pg.yml --tags kernel
}

cloudflare () {
ansible-playbook /opt/plexguide/menu/pg.yml --tags cloudflare
}

nvidia () {
ansible-playbook /opt/plexguide/menu/pg.yml --tags nvidia
}

emergency() {
variable /var/plexguide/emergency.display "On"
if [[ $(ls /opt/appdata/plexguide/emergency) != "" ]]; then
Expand Down
5 changes: 4 additions & 1 deletion menu/pg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
- { role: autodelete, tags: ['autodelete'] }
- { role: clean, tags: ['clean'] }
- { role: clean-encrypt, tags: ['clean-encrypt'] }
- { role: kernel, tags: ['kernel'] }
- { role: kernel, tags: ['kernel'] }
- { role: cloudflare, tags: ['cloudflare'] }
- { role: nvidia, tags: ['nvidia'] }
- { role: system, tags: ['system'] }
40 changes: 40 additions & 0 deletions menu/roles/cloudflare/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#########################################################################
# Title: Cloudbox: Cloudflare Role #
# Author(s): l3uddz, desimaniac #
# URL: https://github.com/cloudbox/cloudbox #
# -- #
# Part of the Cloudbox project: https://cloudbox.works #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---
- name: Install 'dnsutils'
apt: "name=dnsutils state=present"

- name: Get Public IP Address
shell: dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'\"' '{ print $2}'
register: public_ip_lookup

- name: Set 'public_ip' variable
set_fact:
public_ip: "{{ public_ip_lookup.stdout }}"

- name: Set 'record' variable
set_fact:
record: "{{ (subdomain == user.domain) | ternary(user.domain,subdomain + '.' + user.domain) }}"

- name: Set DNS Record
cloudflare_dns:
account_api_token: "{{ cloudflare.api }}"
account_email: "{{ cloudflare.email }}"
zone: "{{ user.domain }}"
state: present
solo: true
proxied: no
type: A
value: "{{ public_ip }}"
record: "{{ subdomain }}"

- name: Display DNS Record
debug:
msg: "DNS Record for '{{ record }}' set to '{{ public_ip }}'."
3 changes: 3 additions & 0 deletions menu/roles/nvidia/files/blacklist-nouveau.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# generated by cloudbox nvidia role
blacklist nouveau
options nouveau modeset=0
110 changes: 110 additions & 0 deletions menu/roles/nvidia/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#########################################################################
# Title: Cloudbox: Nvidia Role #
# Author(s): desimaniac, l3uddz #
# URL: https://github.com/cloudbox/cloudbox #
# -- #
# Part of the Cloudbox project: https://cloudbox.works #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---
- name: Install common pip modules
pip:
state: present
name:
- jmespath

- name: Fetch Nvidia card info
shell: |
if [ `lspci | grep -c -E '.*VGA.*NVIDIA'` -eq 1 ]; then
lspci -s $(lspci | grep -E '.*VGA.*NVIDIA' | cut -d' ' -f 1)
else
echo ""
fi
register: lspci_resp

- name: Nvidia Setup block
block:

# Install Ubuntu drivers

- name: Install Ubuntu drivers
apt:
name: ubuntu-drivers-common
update_cache: yes
state: present

- name: Get list of devices
shell: ubuntu-drivers devices
register: ubuntu_devices

# Install Nvidia Drivers

- name: Nvidia Kernel and Driver Tasks
block:

- name: Check if 'blacklist-nouveau.conf' exists
stat:
path: "/etc/modprobe.d/blacklist-nouveau.conf"
register: blacklist_nouveau_conf

- name: "Nvidia Kernel Task"
include_tasks: "nvidia_kernel.yml"
when: (not blacklist_nouveau_conf.stat.exists)

- name: "Nvidia Driver Task"
include_tasks: "nvidia_driver.yml"

when: '("manual_install: True" not in ubuntu_devices.stdout)'

# Install Nvidia Driver Patch to remove transcode limit

- name: Nvidia Driver Patch Tasks
block:

- name: Check to see if patch backup files exist
find:
paths: "/opt/nvidia/libnvidia-encode-backup"
file_type: file
recurse: yes
patterns: '*.so*'
register: nvidia_patch_backup_files

- name: "Nvidia Driver Patch Task"
include_tasks: "nvidia_patch.yml"
when: (nvidia_patch_backup_files.matched|int == 0)

when: ('GeForce' in lspci_resp.stdout)

# Install Nvidia Runtime Container

- name: Nvidia Runtime Container Tasks
block:

- name: Get contents of 'daemon.json'
shell: cat /etc/docker/daemon.json
register: docker_daemon_json

- name: Set 'docker_default_runtime'
set_fact:
docker_default_runtime: "{{ docker_daemon_json.stdout | from_json | json_query('\"default-runtime\"') }}"

- name: "Nvidia Docker Task"
include_tasks: "nvidia_docker.yml"
when: (docker_default_runtime != 'nvidia')

# Install Nvidia Nvtop Tool

- name: Nvidia Nvtop Tasks
block:

- name: Check nvtop exists
stat:
path: "/usr/local/bin/nvtop"
register: nvtop_binary

- name: "Nvidia Nvtop Task"
include_tasks: "nvidia_nvtop.yml"
when: not nvtop_binary.stat.exists

when: (ansible_distribution == 'Ubuntu') and ('NVIDIA' in lspci_resp.stdout)
65 changes: 65 additions & 0 deletions menu/roles/nvidia/tasks/nvidia_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#########################################################################
# Title: Nvidia: Nvidia Docker Task #
# Author(s): desimaniac, l3uddz #
# URL: https://github.com/cloudbox/cloudbox #
# -- #
# Part of the Cloudbox project: https://cloudbox.works #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---
- name: Add nvidia repository
shell: |
curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \
sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \
sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
- name: Install 'nvidia-container-runtime'
apt:
name: nvidia-container-runtime
update_cache: yes
state: present

- name: Populate Service Facts
service_facts:

- name: Get Docker service state
set_fact:
docker_service_running: "{{ (services['docker.service'] is defined) and (services['docker.service']['state'] == 'running') }}"

- name: Gather list of running Docker containers
shell: "docker ps --format '{{ '{{' }} .Names{{ '}}' }}' | xargs echo -n"
register: docker_running_containers
ignore_errors: yes
when: (docker_service_running)

- name: Stop all running Docker containers
shell: "docker stop {{ docker_running_containers.stdout }}"
ignore_errors: yes
when: (docker_service_running) and not (docker_running_containers.stdout | trim | length == 0)

- name: Stop docker service
systemd:
name: docker
state: stopped
when: (docker_service_running)

# https://github.com/linkernetworks/vortex-installer/blob/master/roles/common/tasks/nvidia-docker.yml
- name: Add runtime to '/etc/docker/daemon.json'
shell: |
jq '."default-runtime" = "nvidia" | .runtimes.nvidia.path = "/usr/bin/nvidia-container-runtime" | .runtimes.nvidia.runtimeArgs = []' \
/etc/docker/daemon.json | jq . > /etc/docker/daemon.json_tmp \
&& mv /etc/docker/daemon.json_tmp /etc/docker/daemon.json
- name: Start docker service
systemd:
name: docker
state: started
when: (docker_service_running)

- name: "Re-start all previously running Docker containers"
shell: 'docker start {{ docker_running_containers.stdout }}'
ignore_errors: yes
when: (docker_service_running) and not (docker_running_containers.stdout | trim | length == 0)
42 changes: 42 additions & 0 deletions menu/roles/nvidia/tasks/nvidia_driver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#########################################################################
# Title: Nvidia: Nvidia Driver Task #
# Author(s): desimaniac, l3uddz #
# URL: https://github.com/cloudbox/cloudbox #
# -- #
# Part of the Cloudbox project: https://cloudbox.works #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---
- name: Download Nvidia drivers
get_url:
url: "https://download.nvidia.com/XFree86/Linux-x86_64/410.78/NVIDIA-Linux-x86_64-410.78.run"
dest: /tmp/NVIDIA-Linux-x86_64-410.78.run
mode: 0775
owner: root
group: root
force: yes
validate_certs: no
register: driver_download

- name: Install 'build-essential'
apt:
name: build-essential
update_cache: yes
state: present

- name: Install Nvidia drivers
shell: /tmp/NVIDIA-Linux-x86_64-410.78.run --silent
register: driver_install
ignore_errors: yes

- name: Nvidia driver did not install
debug:
when: (driver_install is failed) or ('ERROR' in driver_install.stdout)

- name: Nvidia driver did not install
fail:
msg:
- "{{ driver_install.stdout }}"
- "Nvidia driver did not install"
when: (driver_install is failed) or ('ERROR' in driver_install.stdout)
37 changes: 37 additions & 0 deletions menu/roles/nvidia/tasks/nvidia_kernel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#########################################################################
# Title: Nvidia: Nvidia Kernel Task #
# Author(s): desimaniac, l3uddz #
# URL: https://github.com/cloudbox/cloudbox #
# -- #
# Part of the Cloudbox project: https://cloudbox.works #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---
- name: Copy 'blacklist-nouveau.conf'
copy:
src: "blacklist-nouveau.conf"
dest: "/etc/modprobe.d/blacklist-nouveau.conf"
owner: "root"
group: "root"
mode: 0664
register: r

- name: Continue with tasks
block:

- name: Success message
debug:
msg: "Disabled nouveau driver. System will now reboot ..."

- name: Update initramfs
command: update-initramfs -u

- name: Reboot command
shell: reboot

- name: Reboot message
fail:
msg: "Disabled nouveau driver. You will need to restart the server for changes to take effect."

when: (r.changed)
39 changes: 39 additions & 0 deletions menu/roles/nvidia/tasks/nvidia_nvtop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#########################################################################
# Title: Nvidia: Nvidia Nvtop Task #
# Author(s): desimaniac, l3uddz #
# URL: https://github.com/cloudbox/cloudbox #
# -- #
# Part of the Cloudbox project: https://cloudbox.works #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---
- name: Install nvtop dependencies
apt: name="{{ item }}" state=present update_cache=yes
become: true
with_items:
- cmake
- libncurses5-dev
- libncursesw5-dev

- name: Pull nvtop repo from github
git: clone=yes repo=https://github.com/Syllo/nvtop dest=/tmp/nvtop/
register: diff

- name: Build and install nvtop
shell: "cd /tmp/nvtop && \
mkdir build && \
cd build && \
cmake .. -DNVML_RETRIEVE_HEADER_ONLINE=True && \
make && \
make install"
when: diff.changed

- name: "Get nvtop version"
shell: "/usr/local/bin/nvtop --version | head -n 1 | awk '{print $3}' | cut -f1,2 -d'-'"
register: nvtop_version
ignore_errors: yes

- name: "Display nvtop version"
debug:
msg: "nvtop {{ nvtop_version.stdout }} installed."
Loading

0 comments on commit 23e21b8

Please sign in to comment.