I would like to have a mechanism to set up a server automagically…
I would like to have a mechanism to set up a server automagically…
Similarly I would like to set up my user account settings (Tmux plugins, .zshrc and vim settings, etc) that I can replicate in multiple machines via a script (I have a custom script for this but I want a more solid alternative)
I completely agree. But I'm working from the assumption that if OP actually needs the ability to automatically provisions platforms, they're probably working at a larger scale than the typical small self-hosted home server. And I like to give options.
IMO, the only tools here that most self hosters need are Docker, and maybe Ansible, though even that is a stretch because in most cases you're just going to have one server running all your containers and that's it.
It's the whole "Cattle vs Pets" question. When you're a typical self hoster, you're probably better off just treating every server as a pet. But if you're using self hosting as a way of building job skills (which is exactly how I broke into IT) then you absolutely want to start learning how to wrangle cattle.
You're probably looking for some sort of configuration management tool like chef, ansible, saltstack, or puppet. If you're not already familiar with one, ansible is pretty easy to get started with.
If you're also wanting something that can create the server itself, terraform is great and supports most cloud providers and supervisors.
If you don't update your Docker images for two years or more you are going to have even more security holes than if you had it all on the host system and didn't update that.
Why is infra as a code so sought after? I feel like this is installation scripts and config like bare bones, but you need another layer to make it work on top. What am I missing?
Not sure why you would use it for a single server with a single admin you only install once but for multiple admins and many servers it provides repeatable results that are the same no matter who does it and it also allows you to add small settings that you would never do by hand every time you install a new machine. There is nothing worse than discovering that your dev system and your production system differ in a minor way that makes a test succeed on dev but fail on production because of something someone installed or configured manually. Well, apart from discovering that same thing happened with your 5 year old production server you are trying to reinstall after it broke.
The difference between an Anible playbook and a script, is Ansible has a 'check', 'change', 'verify' pattern, and is declarative (meaning that once the playbook is made, it tends to keep working on future versions of Ansible.)
Bare metal servers, VPSs, or VM's you host? If it's for VM's you host, then consider Proxmox as hypervisor and use VM templates. I'm sure old school sysops could to the same with QEMU and Virtmanager or something. But basically, I just set up a VM exactly how I like it, then convert it to a template and cookie cutter it out.
I can sense the Nix guys shaking their heads - it's on my list to try :- )