Hello, I have recently been seeing a boom in people using ansible for automating setting up vps’s, services, …
Is it worth it to learn ansible to do also automate the way I setup everything, or is a bash script good enough ( I know some bash scripting but ansible seems like it could be more worth the time to learn )?
I think it is a great way to document what you have done too. Especially with larger setups this can be quite time-intensive.
Then add that you may want to dynamically reconfigure your systems to interact with each other and then Ansibles template-rendering comes in really handy.
Finally, it is standardized - so other peopke can work with it too (relevant in work context).
This sounds amazing!
You have any good resources to recommend for learning ansible?
I recently began learning Ansible and this playlist was very helpful with learning.
Here is an alternative Piped link(s):
Piped is a privacy-respecting open-source alternative frontend to YouTube.
I’m open-source; check me out at GitHub.
Sorry, but I fear not. Ansible has a good getting started out there, but I think you’ll learn the most just using it.
Maybe a broad roadmap… Try to add systems. Test them via Ansible-Ping. Change some configs (add file, add line-in-file). Add handlers to react to changes by restarting services. Add host variables and customize behavior per host. Add templates…
Learn Linux TV has a good series as does Jeff Geerling both are free on YouTube.
I prefer the Learn Linux TV one as it goes through how to integrate git and different distros.
I use it and I like it, but other people have their own favorites. The online docs are fine.
Configuration management and build automation are definitely worth the time and effort of learning. It doesn’t have to be ansible, find which tool suits your needs.
IMHO Ansible isn’t much different than a bash script… it has the advantage of being “declarative” (in quotes because it’s not actually declarative at all: it just has higher-level abstractions that aggregate common sysadmin CLI operations/patterns in “declarative-sounding” tasks), but it also has the disadvantage of becoming extremely convoluted the moment you need any custom logic whatsoever (yes, you can write a python extension, but you can do the same starting with a bash script too).
Also, you basically can’t use ansible unless your target system has python (technically you can, but in practice all the useful stuff needs python), meaning that if you use a distro that doesn’t come with python per default (eg. alpine) you’ll have to manually install it or write some sort of pythonless prelude to your ansible script that does that for you, and that if your target can’t run python (eg. openwrt on your very much resource-constrained wifi APs) ansible is out of the question (technically you can use it, but it’s much more complex than not using it).
My two cents about configuration management for the homelab:
- whatever you use, make sure it’s something you re-read often: it will become complex and you will forget everything about it
- keep in mind that you’ll have to re-test/update your scripts at least everytime your distro version changes (eg. if you upgrade from ubuntu 22.04 to 24.04) and ideally every time one of your configured services changes (because the format of their config files may in theory change too)
- if you can cope with a rolling-style distro, take a look at nix instead of “traditional” configuration management: nixos configuration is declarative and (in theory) guarantees that you won’t ever need to recheck or update your config when updating (in reality, you’ll occasionally have to edit your config, but the OS will tell you so it’s not like you can unknowingly break stuff).
BTW, nixos is also not beginner-friendly in the least and all in all badly documented (documentation is extensive but unfriendly and somewhat disorganized)… good luck with that :)
You will hate Ansible if you are coming from Nix. I went the other way and Nix is 1000x cleaner.
Being able to actually reverse changes is trivial in Nix, but can be a headache in Ansible. Not to mention the advantages of writing in an actual language and not yaml full of template hacks. I personally don’t see much future for tools like Ansible, there is considerable inertia working in its favor right now and it is absolutely true that it is widely used, but the future of configuration management is for sure more aligned with how Nix works.
I have been setting it up on my home, still not done but I can already see some benefits from it, e.g. I’m about to build a new server and migrate a lot of stuff to it, with ansible it will be very easy to just move some configs around and setup the server in no time at all. It also is encouraging me to keep a standard on how I do things which is great, and after setting up some initial things now adding new services is quite straightforward.
Overall I think there are a lot of positives about it, especially if you have multiple machines to manage. But even for a single one the fact that you can recreate everything from scratch in just one command is quite awesome considering the amount of times I’ve redone my server from 0 for different reasons over the past years.