Skip to content
This repository was archived by the owner on Jun 7, 2025. It is now read-only.
/ homelab Public archive

A collection of infrastructure-as-code (IaC) and configuration-as-code (CaC) files for homelab setup.

Notifications You must be signed in to change notification settings

gillwong/homelab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Homelab

Introduction

A collection of infrastructure-as-code (IaC) and configuration-as-code (CaC) files for homelab setup.

OpenTofu (an open-source fork of Terraform) is used to provision infrastructure in Proxmox Virtual Environment (VE) through IaC while Vagrant is used for testing Ansible playbooks, which is configuration-as-code used to automate infrastructure configuration.

Getting Started

The homelab can be configured using either OpenTofu/Terraform or Vagrant. OpenTofu/Terraform is used to provision infrastructure under the infra/prod directory while Vagrant is used for provisioning infrastructure under the infra/test directory. After provisioning, Ansbile is then used to run playbooks under the provisioning/playbooks directory.

Prerequisites

  1. Install IaC tools: OpenTofu (guide) or Terraform (guide), and Vagrant (guide)

  2. Install CaC tools: Ansible (guide). There are requirements.txt and .python-version files under the provisioning directory which can be used if installing Ansible using pip

Setup IaC

Setup Proxmox

  1. Setup a Proxmox VE server (guide) and follow this guide to create user for the Terraform Proxmox VE provider

  2. Create a Proxmox VE VM template using this guide. The homelab uses AlmaLinux OS 9 (an open-source Linux distribution binary compatible with RHEL) and ID 90x for the VM templates by default. Create one VM template for each Proxmox VE node. Obtain the cloud-init images for AlmaLinux here. Note that the snippet provided in the guide will be replaced via Ansible later on in this "Getting Started" guide.

  3. View the Terraform files and make changes as necessary, e.g., the Proxmox VE API URL for the provider, network and disk settings for the VM, etc. Optionally, create an .auto.tfvars file to store variables

Setup Vagrant

  1. Install Vagrant Libvirt using this guide

Setup CaC

  1. Add a generic password to the macOS keychain:
security add-generic-password -s homelab-playbooks -a ansible-vault -w
  1. Replace all vault.yaml files and encrypt them using Ansible Vault

  2. View the inventory file hosts-prod.yaml and make changes as necessary

  3. View variables under the provisioning/group_vars/ directory and make changes as necessary

Provisioning

Using OpenTofu/Terraform

Provision infrastructure using OpenTofu (replace tofu with terraform if using Terraform). Example:

cd infra/prod/k8s
tofu init
tofu plan -out=plan0
tofu apply plan0

Bootstrap using the Ansible playbooks. Example:

Note

Copy all SSH hosts keys to ~/.ssh/known_hosts before running the playbooks (adjust IP address range to match your environment):

for ip in 192.168.1.{21..26}; do ssh-keyscan -H $ip >> ~/.ssh/known_hosts; done
cd ../../../provisioning
ansible-playbook playbooks/k8s.yaml --inventory=hosts-prod.yaml

Using Vagrant

Provision infrastructure using Vagrant (automatically runs the Ansible playbooks). Example:

cd infra/test/k8s
vagrant up

Destroying

Destroy infrastructure using OpenTofu (replace tofu with terraform if using Terraform). Example:

cd infra/prod/k8s
tofu destroy

Or using Vagrant:

cd infra/test/k8s
vagrant destroy

About

A collection of infrastructure-as-code (IaC) and configuration-as-code (CaC) files for homelab setup.

Resources

Stars

Watchers

Forks