More Reasons Infrastructure as Code is Awesome

2 minute read

Why IaC is Awesome

Working with Ansible to configure my homelab has shown me just how essential Infrastructure as Code really is. When you hear about IaC, you mostly hear about things like preventing environment drift, easily setting up new environments, and getting stricter control over infrastructure. Those are great things to have, but I think there are some other really good reasons that people should consider IaC.

It helps you recover from mistakes

Even though I’ve only been working on this homelab for a little under a year now, I’ve already had 2 occasions where I’d probably have stopped working on it if it weren’t for Ansible. The first time is 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, 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.

It documents what you have

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.

Balancing Cost and Benefit

When you’re working on a side project, one major thing to consider is where you spend your time. I’m usually only able to spend a lot of time on these projects on weekends, and sometimes I’m not able to come back to it for weeks. So, keeping focused on actually producing something is important. I can’t just keep bouncing from project to project or shiny toy to shiny toy. IaC is one of those cases where you get a lot back for your investment, especially when you feel like you may not have the time to invest in the first place. It’s a great insurance policy for hobby projects, in addition to being something enterprises are adopting to manage infrastructure much more complex than anything in my homelab.

Updated: