Skip to content

Commit

Permalink
v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maximxmoroz committed Oct 16, 2024
1 parent 9f7d10e commit c7b2147
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 175 deletions.
42 changes: 10 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
# Fresh install
1. Go Root:
```
sudo su
```
2. Install Ansible:
```
sudo apt install -y software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install -y ansible
```
3. Git Clone Repo:
```
git clone https://github.com/ &&
cd ansibledirectory
```
4. Setup Docker with Ansible:
```
ansible-playbook docker.yaml
```
5. Setup Nvidia drivers:
```
ansible-playbook nvidia.yaml
```
6. Reboot the system for the changes to take effect:
```
sudo reboot
```
7. Install Nvidia container runtime for docker:
```
ansible-playbook nvidia-container.yaml
```
# Install ansible on your local pc/laptop
```brew install ansible```
# Add some info to inventories/hosts.ini
To ansible_host add Domain or IP address of your server
To ansible_user add name of user from your server
To ansible_become_password add password from your server
# Add your ssh key to ssh-agent localy
```ssh-add ~/.ssh/id_rsa```
# Start script
```ansible-playbook -i inventories/hosts.ini install.yaml```
Empty file removed bred.txt
Empty file.
70 changes: 0 additions & 70 deletions docker.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Install
hosts: all
become: yes
roles:
- install
2 changes: 2 additions & 0 deletions inventories/hosts.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[main]
server ansible_host= ansible_user= ansible_become_password=
5 changes: 0 additions & 5 deletions inventory.ini

This file was deleted.

14 changes: 0 additions & 14 deletions main.yaml

This file was deleted.

35 changes: 0 additions & 35 deletions nvidia-container.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions nvidia.yaml

This file was deleted.

67 changes: 67 additions & 0 deletions roles/install/tasks/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
- name: Update package list
become: yes
apt:
update_cache: yes

- name: Install required packages
become: yes
apt:
name:
- ca-certificates
- curl
- net-tools
- apt-transport-https
- software-properties-common
- python3-pip
- virtualenv
- python3-setuptools
- gnupg-agent
- autoconf
- dpkg-dev
- file
- g++
- gcc
- libc-dev
- make
- pkg-config
- re2c
- wget

- name: Create /etc/apt/keyrings directory
become: yes
file:
path: /etc/apt/keyrings
state: directory
mode: "0755"

- name: Download and install Docker GPG keyring
become: yes
shell: "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg"

- name: Add Repo
ansible.builtin.apt_repository:
filename: docker.gpg
repo: "deb [arch={{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }} signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present

- name: Update package
become: yes
apt:
update_cache: yes

- name: Install docker
ansible.builtin.apt:
name: ["docker-ce", "docker-ce-cli", "containerd.io"]
state: latest
update_cache: true

- name: Install docker-compose from official github repo
ansible.builtin.get_url:
url: https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64
dest: /usr/local/bin/docker-compose
mode: "u+x,g+x"

- name: Install Docker Module for Python
ansible.builtin.pip:
name: docker
4 changes: 4 additions & 0 deletions roles/install/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- import_tasks: docker.yaml
- import_tasks: nvidia.yaml
- import_tasks: nvidia-container.yaml
31 changes: 31 additions & 0 deletions roles/install/tasks/nvidia-container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: Add NVIDIA Docker GPG key
ansible.builtin.apt_key:
url: "https://nvidia.github.io/nvidia-docker/gpgkey"
state: present

- name: Add NVIDIA Docker repository
ansible.builtin.get_url:
url: "https://nvidia.github.io/nvidia-docker/{{ ansible_distribution|lower }}{{ ansible_distribution_version }}/nvidia-docker.list"
dest: "/etc/apt/sources.list.d/nvidia-docker.list"
mode: "0644"
owner: "root"
group: "root"

- name: Update apt cache
ansible.builtin.apt:
update_cache: yes

- name: Install NVIDIA container runtime
ansible.builtin.apt:
name: nvidia-container-runtime
state: present

- name: Restart Docker service
ansible.builtin.systemd:
name: docker
state: restarted

- name: Run NVIDIA container
ansible.builtin.command:
cmd: "docker run --gpus all nvidia/cuda:12.3.1-base-ubuntu22.04 nvidia-smi"
29 changes: 29 additions & 0 deletions roles/install/tasks/nvidia.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Add Nvidia Graphics Drivers PPA
ansible.builtin.apt_repository:
repo: "ppa:graphics-drivers/ppa"
state: present
filename: nvidia-graphics-drivers-ppa

- name: Install Ubuntu drivers
ansible.builtin.apt:
name: ubuntu-drivers-common
state: present

- name: Install Nvidia driver version custom
ansible.builtin.apt:
name: nvidia-driver-530
state: present

- name: Reboot server
ansible.builtin.reboot:
reboot_timeout: 600
ignore_errors: yes

- name: Wait for the server to be back online
ansible.builtin.wait_for_connection:
timeout: 300

- name: Continue tasks after reboot
ansible.builtin.shell: |
echo "Server is back online, continuing tasks..."

0 comments on commit c7b2147

Please sign in to comment.