mirror of
https://github.com/rodneyosodo/homelab.git
synced 2026-06-23 04:10:19 +00:00
feat(ansible): Add ansible playbook to boostrap the homelab
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
.PHONY: install
|
||||
install:
|
||||
ansible-galaxy role install ctorgalson.nerdfonts
|
||||
|
||||
.PHONY: ping
|
||||
ping:
|
||||
ansible-playbook playbooks/ping.yaml
|
||||
|
||||
.PHONY: setup-odin
|
||||
setup-odin:
|
||||
ansible-playbook playbooks/odin.yaml
|
||||
|
||||
.PHONY: setup-bohr
|
||||
setup-bohr:
|
||||
ansible-playbook playbooks/bohr.yaml
|
||||
|
||||
.PHONY: install-zsh
|
||||
install-zsh:
|
||||
ansible-playbook playbooks/zsh.yaml
|
||||
|
||||
.PHONY: setup-homelab
|
||||
setup-homelab:
|
||||
ansible-playbook playbooks/homelab.yaml
|
||||
@@ -0,0 +1,7 @@
|
||||
# Ansible Playbooks
|
||||
|
||||
This directory contains the Ansible playbooks for my homelab.
|
||||
|
||||
## Requirements
|
||||
|
||||
- [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)
|
||||
@@ -0,0 +1,5 @@
|
||||
[defaults]
|
||||
INVENTORY = ./inventory/hosts.yaml
|
||||
|
||||
[ssh_connection]
|
||||
pipelining = True
|
||||
@@ -0,0 +1,43 @@
|
||||
servers:
|
||||
hosts:
|
||||
odin:
|
||||
ansible_host: odin
|
||||
ansible_connection: ssh
|
||||
ansible_user: root
|
||||
bohr:
|
||||
ansible_host: bohr
|
||||
ansible_connection: ssh
|
||||
ansible_user: rodneyosodo
|
||||
|
||||
pc:
|
||||
hosts:
|
||||
thor:
|
||||
ansible_host: thor
|
||||
ansible_connection: ssh
|
||||
ansible_user: rodneyosodo
|
||||
|
||||
laptop:
|
||||
hosts:
|
||||
snotra:
|
||||
ansible_host: snotra
|
||||
|
||||
backup:
|
||||
hosts:
|
||||
heimdall:
|
||||
ansible_host: heimdall
|
||||
ansible_connection: ssh
|
||||
ansible_user: rodneyosodo
|
||||
|
||||
kubernetes:
|
||||
hosts:
|
||||
frigg:
|
||||
ansible_host: frigg
|
||||
ansible_connection: ssh
|
||||
|
||||
loki:
|
||||
ansible_host: loki
|
||||
ansible_connection: ssh
|
||||
|
||||
baldr:
|
||||
ansible_host: baldr
|
||||
ansible_connection: ssh
|
||||
@@ -0,0 +1,95 @@
|
||||
# Set the directory we want to store zinit and plugins
|
||||
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
|
||||
|
||||
# Download Zinit, if it's not there yet
|
||||
if [ ! -d "$ZINIT_HOME" ]; then
|
||||
mkdir -p "$(dirname $ZINIT_HOME)"
|
||||
git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
|
||||
fi
|
||||
|
||||
# Download fzf, if it's not installed
|
||||
if [ ! -d "$HOME/.fzf" ]; then
|
||||
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
|
||||
$HOME/.fzf/install
|
||||
fi
|
||||
|
||||
# Source/Load zinit
|
||||
source "${ZINIT_HOME}/zinit.zsh"
|
||||
|
||||
# Add in Powerlevel10k
|
||||
zinit ice depth=1; zinit light romkatv/powerlevel10k
|
||||
|
||||
# Add in zsh plugins
|
||||
zinit light zsh-users/zsh-syntax-highlighting
|
||||
zinit light zsh-users/zsh-completions
|
||||
zinit light zsh-users/zsh-autosuggestions
|
||||
zinit light Aloxaf/fzf-tab
|
||||
|
||||
# Add in snippets
|
||||
zinit snippet OMZP::git
|
||||
zinit snippet OMZP::ssh-agent
|
||||
zinit snippet OMZP::bgnotify
|
||||
zinit snippet OMZP::dotenv
|
||||
zinit snippet OMZP::git-prompt
|
||||
zinit snippet OMZP::virtualenv
|
||||
zinit snippet OMZP::aliases
|
||||
zinit snippet OMZP::kubectl
|
||||
zinit snippet OMZP::kubectx
|
||||
zinit snippet OMZP::command-not-found
|
||||
|
||||
# Load completions
|
||||
autoload -Uz compinit && compinit
|
||||
|
||||
zinit cdreplay -q
|
||||
|
||||
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
|
||||
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
|
||||
|
||||
# Keybindings
|
||||
bindkey -e
|
||||
bindkey '^p' history-search-backward
|
||||
bindkey '^n' history-search-forward
|
||||
bindkey '^[w' kill-region
|
||||
|
||||
# History
|
||||
HISTSIZE=5000
|
||||
HISTFILE=~/.zsh_history
|
||||
SAVEHIST=$HISTSIZE
|
||||
HISTDUP=erase
|
||||
setopt appendhistory
|
||||
setopt sharehistory
|
||||
setopt hist_ignore_space
|
||||
setopt hist_ignore_all_dups
|
||||
setopt hist_save_no_dups
|
||||
setopt hist_ignore_dups
|
||||
setopt hist_find_no_dups
|
||||
|
||||
# Completion styling
|
||||
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
|
||||
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
|
||||
zstyle ':completion:*' menu no
|
||||
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath'
|
||||
|
||||
zstyle :omz:plugins:ssh-agent agent-forwarding yes
|
||||
zstyle :omz:plugins:ssh-agent identities github
|
||||
zstyle :omz:plugins:ssh-agent lifetime 30d
|
||||
|
||||
|
||||
# Aliases
|
||||
alias ls='ls --color'
|
||||
alias c='clear'
|
||||
|
||||
# Shell integrations
|
||||
eval "$(fzf --zsh)"
|
||||
eval `ssh-agent -s`
|
||||
|
||||
if [ -f "~/.ssh/github" ]; then
|
||||
ssh-add ~/.ssh/github
|
||||
fi
|
||||
|
||||
# Functions
|
||||
function genpasswd() {
|
||||
local length=$1
|
||||
[ -z "$length" ] && length=16
|
||||
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${length} | xargs
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
- name: Setup Docker Server
|
||||
hosts: "bohr"
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Update package lists
|
||||
ansible.builtin.apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: Update all packages to their latest version
|
||||
ansible.builtin.apt:
|
||||
name: "*"
|
||||
state: latest
|
||||
|
||||
- name: Remove useless packages from the cache
|
||||
ansible.builtin.apt:
|
||||
autoclean: yes
|
||||
|
||||
- name: Remove dependencies that are no longer required and purge their configuration files
|
||||
ansible.builtin.apt:
|
||||
autoremove: yes
|
||||
purge: true
|
||||
|
||||
- name: Run the equivalent of "apt-get clean" as a separate step
|
||||
ansible.builtin.apt:
|
||||
clean: yes
|
||||
|
||||
- name: Install Applications
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- git
|
||||
- tar
|
||||
- p7zip
|
||||
- unzip
|
||||
- curl
|
||||
- wget
|
||||
- gcc
|
||||
- g++
|
||||
- make
|
||||
- vim
|
||||
- zsh
|
||||
- python3
|
||||
- ripgrep
|
||||
- fd-find
|
||||
- bpytop
|
||||
- thefuck
|
||||
- fontconfig
|
||||
- nala
|
||||
- qemu-guest-agent
|
||||
state: present
|
||||
|
||||
- name: Setup Neovim
|
||||
ansible.builtin.shell: |
|
||||
curl -sL https://github.com/neovim/neovim/releases/latest/download/nvim-linux64.tar.gz | sudo tar -xzf - --strip-components=1 --overwrite -C /usr
|
||||
rm -rf ~/.config/nvim
|
||||
git clone https://github.com/LazyVim/starter ~/.config/nvim
|
||||
rm -rf ~/.config/nvim/.git
|
||||
@@ -0,0 +1,34 @@
|
||||
- name: Setup Docker Server
|
||||
hosts: "bohr"
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Install Applications
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- git
|
||||
|
||||
- name: Setup Homelab
|
||||
ansible.builtin.shell: |
|
||||
cd /home/{{ ansible_user }}
|
||||
mkdir -p docker-volumes
|
||||
if [ ! -d "homelab" ]; then
|
||||
git clone https://github.com/rodneyosodo/homelab.git
|
||||
cd homelab
|
||||
fi
|
||||
cd homelab
|
||||
if [ ! -f "docker-compose/default.env" ]; then
|
||||
cp docker-compose/default.env docker-compose/.env
|
||||
fi
|
||||
docker compose -f docker-compose/docker-compose.yaml pull
|
||||
|
||||
- name: Recursively change ownership of a directory
|
||||
ansible.builtin.file:
|
||||
path: /home/{{ ansible_user }}/homelab/
|
||||
state: directory
|
||||
recurse: yes
|
||||
owner: "{{ ansible_user }}"
|
||||
group: "{{ ansible_user }}"
|
||||
|
||||
- name: Print message
|
||||
ansible.builtin.debug:
|
||||
msg: Populate environment variables in homelab/docker-compose/default.env
|
||||
@@ -0,0 +1,121 @@
|
||||
- name: Setup proxmox server
|
||||
hosts: "odin"
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Add Proxmox repository to sources.list
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/apt/sources.list
|
||||
line: deb http://download.proxmox.com/debian bookworm pve-no-subscription
|
||||
state: present
|
||||
create: true
|
||||
mode: 0644
|
||||
owner: root
|
||||
group: root
|
||||
|
||||
- name: Comment out enterprise repository
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/apt/sources.list.d/pve-enterprise.list
|
||||
line: deb https://enterprise.proxmox.com/debian/pve bookworm pve-enterprise
|
||||
state: absent
|
||||
create: true
|
||||
mode: 0644
|
||||
owner: root
|
||||
group: root
|
||||
|
||||
- name: Comment out ceph repository
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/apt/sources.list.d/ceph.list
|
||||
line: deb https://enterprise.proxmox.com/debian/ceph-quincy bookworm enterprise
|
||||
state: absent
|
||||
create: true
|
||||
mode: 0644
|
||||
owner: root
|
||||
group: root
|
||||
|
||||
- name: Update package lists
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: Update all packages to their latest version
|
||||
ansible.builtin.apt:
|
||||
name: "*"
|
||||
state: latest
|
||||
|
||||
- name: Remove useless packages from the cache
|
||||
ansible.builtin.apt:
|
||||
autoclean: true
|
||||
|
||||
- name: Remove dependencies that are no longer required and purge their configuration files
|
||||
ansible.builtin.apt:
|
||||
autoremove: true
|
||||
purge: true
|
||||
|
||||
- name: Run the equivalent of "apt-get clean" as a separate step
|
||||
ansible.builtin.apt:
|
||||
clean: true
|
||||
|
||||
- name: Enable IOMMU (PCI Passthrough)
|
||||
ansible.builtin.replace:
|
||||
backup: true
|
||||
path: /etc/default/grub
|
||||
regexp: 'GRUB_CMDLINE_LINUX_DEFAULT="quiet"'
|
||||
replace: 'GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on"'
|
||||
|
||||
- name: Edit /etc/modules
|
||||
ansible.builtin.blockinfile:
|
||||
path: /etc/modules
|
||||
prepend_newline: true
|
||||
append_newline: true
|
||||
backup: true
|
||||
create: true
|
||||
mode: 0644
|
||||
owner: root
|
||||
group: root
|
||||
block: |
|
||||
vfio
|
||||
vfio_iommu_type1
|
||||
vfio_pci
|
||||
vfio_virqfd
|
||||
|
||||
- name: Update grub
|
||||
ansible.builtin.command: update-grub
|
||||
|
||||
- name: Install Applications
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- sudo
|
||||
- git
|
||||
- tar
|
||||
- unzip
|
||||
- curl
|
||||
- wget
|
||||
- gcc
|
||||
- g++
|
||||
- make
|
||||
- vim
|
||||
- zsh
|
||||
- python3
|
||||
- ripgrep
|
||||
- fd-find
|
||||
- bpytop
|
||||
- thefuck
|
||||
- fontconfig
|
||||
state: present
|
||||
|
||||
- name: Setup Neovim
|
||||
ansible.builtin.shell: |
|
||||
curl -sL https://github.com/neovim/neovim/releases/latest/download/nvim-linux64.tar.gz | sudo tar -xzf - --strip-components=1 --overwrite -C /usr
|
||||
rm -rf ~/.config/nvim
|
||||
git clone https://github.com/LazyVim/starter ~/.config/nvim
|
||||
rm -rf ~/.config/nvim/.git
|
||||
|
||||
- name: Download microcode updates
|
||||
ansible.builtin.get_url:
|
||||
url: https://github.com/tteck/Proxmox/raw/main/misc/microcode.sh
|
||||
dest: /tmp/install-microcode.sh
|
||||
mode: 0755
|
||||
|
||||
- name: Print message
|
||||
ansible.builtin.debug:
|
||||
msg: Make sure to run bash /tmp/install-microcode.sh to install microcode updates
|
||||
@@ -0,0 +1,9 @@
|
||||
- name: Ping all hosts
|
||||
hosts: "servers"
|
||||
tasks:
|
||||
- name: Ping all hosts
|
||||
ansible.builtin.ping:
|
||||
|
||||
- name: Print message
|
||||
ansible.builtin.debug:
|
||||
msg: Hello world
|
||||
@@ -0,0 +1,47 @@
|
||||
- name: Install zsh
|
||||
hosts: "bohr"
|
||||
vars:
|
||||
nf_user: "{{ ansible_user }}"
|
||||
nf_group: "{{ nf_user }}"
|
||||
nf_single_fonts:
|
||||
- "Meslo/L/Regular/MesloLGLNerdFontMono-Regular.ttf"
|
||||
tasks:
|
||||
- name: Install Git
|
||||
ansible.builtin.package:
|
||||
state: present
|
||||
name: git
|
||||
become: true
|
||||
|
||||
- name: Install Curl
|
||||
ansible.builtin.package:
|
||||
state: present
|
||||
name: curl
|
||||
become: true
|
||||
|
||||
- name: Install zsh
|
||||
ansible.builtin.package:
|
||||
name: zsh
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: Install unzip
|
||||
ansible.builtin.package:
|
||||
name: unzip
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: Ensure zsh is the default shell
|
||||
user:
|
||||
name: "{{ ansible_user }}"
|
||||
shell: "/usr/bin/zsh"
|
||||
become: true
|
||||
|
||||
- name: "Include ansible-role-nerdfonts"
|
||||
include_role:
|
||||
name: "ctorgalson.nerdfonts"
|
||||
|
||||
- name: Copy ZSHRC config
|
||||
ansible.builtin.copy:
|
||||
src: assets/.zshrc
|
||||
dest: ~/.zshrc
|
||||
mode: "0644"
|
||||
Reference in New Issue
Block a user