Why IaC is Awesome (need a better title)

Within the first year of building my homelab, I had 2 occasions where I'd probably have stopped working on it if it weren't for IaC. The first time was when I spent a couple weekends configuring my Pis and struggling to get a DNS server to work, only to find out I had accidentally installed the 32-bit version of Ubuntu and the DNS server needed 64-bit to work. Now, to be honest at that point I didn’t remember a lot of what I had done to configure everything up to that point. If I had to redo all the work I did over the last 2 weekends I would have seriously struggled to stay motivated to work on the project. But, thankfully I had all my configuration written down in YAML files, so all I had to do was reinstall the OS and re-run my playbook. What would have been another couple miserable weekends only took about 15 minutes. That's well worth the extra time it's taken to learn Ansible on top of everything else.

The second time is when I accidentally deleted my entire Kubernetes cluster. Long story short there's a command that lets you delete everything of a certain type in a namespace. Except when you tell that command to delete the namespace itself, it gives you a warning that it can't filter that operation by namespaces and just ignores the filter entirely. So I sat there for 10 very sad minutes while my entire cluster got deleted. Luckily, it took just another 2 minutes to run my Ansible playbooks and recreate everything that got deleted.

Aside from disaster recovery, it’s been extremely useful to use IaC to document what I’m doing. Part of building this homelab has been working on things I'm not very familiar with (administering Ubuntu servers, DNS configuration, etc.). I'm pretty unlikely to remember how I set some of these new things up months after I'm done with them. Luckily, writing out IaC means I can look back at my playbook and see exactly what I did to get there. That helps with troubleshooting as well, since my playbooks often tell me where the log files are.