This repository contains the configuration-as-code for my homelab.
The goal is to automate as much as possible to a reasonable extent. This means that there will be manual intervention involved, such as plugging in IP addresses after VMs are provisioned, and some application configuration after installation.
For the Packer builds to work you will need VMware Workstation (or Fusion if you're on macOS) to be installed.
- SSH access must be enabled temporarily on the ESXi host when running Terraform. (Don't forget to disable this when you're done!)
- By default, Terraform expects a virtual network named "VM Network" (Created by default when ESXi is installed)
- By default, Terraform expects a disk store named "datastore1" (Created by default when ESXi is installed)
- By default, Terraform expects an ESXi user "root" and access on port 22 (Created by default when ESXi is installed)
For all hosts it's a good idea to configure ntpd to start/stop with the host, and set a network time server (e.g. time.nist.gov
).
For the Raspberry Pi ESXi host(s) that you will be using to build the OVA templates you will need to enable GuestIPHack on the host:
esxcli system settings advanced set -o /Net/GuestIPHack -i 1
To use Terraform with ESXi without vCenter (because $$$), I used terraform-provider-esxi.
The terraform-provider-esxi executable should be placed in the terraform/
directory.
This will initialize Terraform, fetch the providers listed in terraform/versions.tf
, and generate an SSH key for Ansible to use.
$ make init
Packer is used to build the base VM images.
$ make image
This is a good time to make a cup of coffee - it'll take a while.
The output .ova
images will be placed in ./packer/output/
.
Terraform is used to stand up the VM hosts on ESXi.
$ make plan-deploy
$ make deploy
If needed, you can destroy the VMs created with Terraform by using:
$ make undeploy
Ansible is used to configure the VM hosts.
$ make install
In following with Ansible principles, this command can be run repeatedly to ensure constant state and apply any updates.
- I followed this guide to create a VM template: https://techexpert.tips/vmware/create-windows-virtual-machine-template-on-vmware-esxi/
- And this repository for help moving from Ubuntu 18.04 to 20.04: https://github.com/rodm/packer-templates
- https://williamlam.com/2020/10/packer-reference-for-photonos-arm-nfs-virtual-appliance-using-ovf-properties-for-esxi-arm.html
- https://github.com/lamw/photonos-arm-nfs-appliance/blob/master/photon.json
- https://www.packer.io/plugins/builders/vmware/iso#building-on-a-remote-vsphere-hypervisor
- https://communities.vmware.com/t5/Open-Virtualization-Format-Tool/Failed-to-deploy-OVA/td-p/1329381
- https://virtualizationreview.com/articles/2020/10/27/esxi-on-arm.aspx
Issues & TODOs:
[ ] Setup a different datastore for the Pi host that's building the templates so we don't take up disk space from VMs [ ] Unable to resize the boot volume for the arm64 templates [ ] Auto resize root volume: https://askubuntu.com/a/937351/919056
Update ESXi hosts:
https://www.vinchin.com/vm-tips/esxi-update-upgrade.html
esxcli system maintenanceMode set -e true
esxcli software vib update -d /vmfs/volumes/datastore1/VMware-ESXi-7.0U3o-22348816-depot.zip --dry-run
esxcli software vib update -d /vmfs/volumes/datastore1/VMware-ESXi-7.0U3o-22348816-depot.zip
esxcli system shutdown reboot -r "ESXi system upgrade"
esxcli system maintenanceMode set -e false
vmware -v
esxcli software profile update -p ESXi-7.0U3o-22348816-standard -d https://hostupdate.vmware.com/sof
tware/VUM/PRODUCTION/main/vmw-depot-index.xml