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 )?

31 points

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 :)

permalink
report
reply
6 points

Fun fact: I actually run nixos on my main pc.

permalink
report
parent
reply
10 points

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.

permalink
report
parent
reply
22 points

Coming from what looks to me like a different perspective to many of the commenters here (Disclosure I am a professional platform engineer):

If you are already scripting your setups then yes you should absolutely learn/use Ansible. The key reasons are that it is robust, explicit, and repeatable- doesn’t matter whether that’s the same host multiple times or multiple hosts. I have lost count of the number of pet Bash scripts I have encountered in various shops, many of them created by quite talented people. They all had problems. Some typical ones:

Issue Example
Most people write bash scripts without dependency checks ‘Of course everyone will have gnu coreutils installed, it’s part of every Linux distro’ - someone runs the script on a Mac
We need to pass this action out to a command-line tool, that’s obvious Fails if command-line tool isn’t available, no handling errors from tool if they aren’t exactly what’s expected
Of course people will realise that they need to run this from an environment prepared in this exact (undocumented) way Someone runs the script in a different environment
Of course people will be running this on x86_64/AMD64, all these third party binaries are available for that Someone runs it on ARM
Of course people will know what to do if the script fails midway through People try to re-run the script when it fails mid-way through and it’s a mess

The thing about Ansible is that it can be modular (if you want) and you can use other people’s code but fundamentally it runs one step at a time. You will know for each step:

  • Are dependencies met?
  • Did that step succeed or fail (in realtime!)?
  • (If it failed) what was the error?
  • (Assuming you have written sane Ansible) you can re-run your playbook at any time to get the ‘same’ result. No worries about being left in an indeterminate state
  • (To an extent) It is self-documenting
  • Host architecture doesn’t really matter
  • Target architecture/OS is specified and clear
permalink
report
reply
4 points
*
Deleted by creator
permalink
report
parent
reply
16 points

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).

permalink
report
reply
2 points

This sounds amazing!

You have any good resources to recommend for learning ansible?

permalink
report
parent
reply
5 points

I recently began learning Ansible and this playlist was very helpful with learning.

permalink
report
parent
reply
2 points

Here is an alternative Piped link(s):

this playlist

Piped is a privacy-respecting open-source alternative frontend to YouTube.

I’m open-source; check me out at GitHub.

permalink
report
parent
reply
4 points

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…

permalink
report
parent
reply
3 points

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.

permalink
report
parent
reply
2 points

Yeah +1 for LLTV

permalink
report
parent
reply
15 points

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.

permalink
report
reply
10 points

if tech is your career then yes.

permalink
report
reply

Luckilly no, just self interest.

permalink
report
parent
reply
4 points

I guess it depends what you’re in to but it doesn’t make much sense for me.

Most everything I do on servers now is in docker containers, and I back up the compose files and data from those so they can be deployed to a new server pretty easily.

Migrating between servers only happens once every several years. I feel like managing an ansible config would just be an additional layer of complexity rather than making it easier. Their isn’t much configuration outside of docker in my case anyway.

permalink
report
parent
reply
1 point
*

I tend to grow my fleet of servers every couple months, and that requires me to once again setup everything from the beginning, settings, sshd, update debian if old version, new user for ssh, docker/podman, …

Quite literally added new vps to my fleet yesterday and spent 4 hourson setting all that up, when it could have been a simple ansible script.

permalink
report
parent
reply

Selfhosted

!selfhosted@lemmy.world

Create post

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don’t control.

Rules:

  1. Be civil: we’re here to support and learn from one another. Insults won’t be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it’s not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don’t duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

Community stats

  • 5K

    Monthly active users

  • 3.6K

    Posts

  • 81K

    Comments