Skip to main content
Homelab as Code: Packer + Terraform + Ansible
Overview

Homelab as Code: Packer + Terraform + Ansible

Merox
Merox HPC Sysadmin
2 min read (5 min read total) · 4 parts
Automation Advanced
Warning

Experimental — not actively maintained. This post documents an older approach from late 2024. The current infrastructure has moved to Talos + FluxCD GitOps for Kubernetes workloads. The Packer + Terraform + Ansible pipeline still works for spinning up standalone Docker VMs on Proxmox, but it’s no longer the primary deploy method and the repo may be behind on dependencies. Treat this as a reference, not a production guide.

This project automates a full homelab deployment — Packer builds the VM template, Terraform provisions it on Proxmox, and Ansible handles everything inside: Docker, Portainer, Traefik, and optional services like a media stack and Homepage dashboard.

Requirements

Note

This project deploys an Ubuntu VM with Docker, Portainer, Media Stack, Traefik, and more. You’ll need:

  1. Proxmox VE for VM management
  2. A fresh LXC to run the deploy script
  3. A DNS server configured for your service domains

Architecture and Source Code

Homelab Architecture Diagram

Source: meroxdotdev/homelab-as-code

What’s in the Repository

The repo covers everything needed to go from zero to a running VM with services:

  • Deploy script — installs dependencies (git, curl, ansible, packer, terraform), clones the repo, and runs the full pipeline
  • ansible/ — roles for Docker, Portainer, Traefik, and optional NFS mounts
  • configs/docker/ — pre-configured services: Homepage, Traefik, media stack
  • packer/ — builds an optimized Ubuntu template for Proxmox
  • terraform/ — VM provisioning with networking and storage, based on the Packer template

Quick Start

Run this on a clean LXC:

Terminal window
bash -c "$(curl -fsSL https://raw.githubusercontent.com/meroxdotdev/homelab-as-code/refs/heads/master/deploy_homelab.sh)"

What the Script Does

The script first asks whether your repository is public or private. For private repos, it generates an SSH key and prompts you to add it as a deploy key in your repo settings. For the public tutorial repo, use https://github.com/meroxdotdev/homelab-as-code.git directly.

Initial Prompt

Edit Confirmation Prompt

Next, it asks whether you’ve already edited the required config files. Type yes to proceed with the Packer → Terraform → Ansible pipeline, or no to exit and review the guides below first.

Downloaded config files land in /home/homelab/.

Configuration Guides

The setup is split across four subposts — go through them in order before running the script:

  1. Ansible Setup — inventory, roles, optional NFS mounts
  2. Services Configuration — Homepage, Media Stack, Traefik
  3. Infrastructure Setup — Packer and Terraform
  4. Deployment & Verification — final steps and checks

Share this post

Related Posts

Introducing merox-erudite: My Customized Astro Blogging Theme

A fork of astro-erudite with comments, analytics, SEO schemas, and an enhanced homepage — built for production blogging.

3 min read

From WordPress to Hugo: My Setup Explained

Why I moved from WordPress to Hugo, and how the site runs today — GitHub Actions, GitHub Pages, and Cloudflare.

2 min read

How to Set Up a K3S Cluster in 2025

Rebuilding my K3s cluster from scratch with Ansible — VM provisioning via Cloud-Init on Proxmox, HA across three nodes, and full automation.

10 min read 4 parts
Loading comments...