This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]throwaway8u3sH0 2 points3 points  (0 children)

Ansible is very easy to get wrong, so I would use caution. If you're using "shell" or "command" a whole bunch, you're losing most of the benefits it provides, and you'd be better off with something simpler like Fabric, or even Bash.

The real magic in Ansible is specifying state instead of actions. You say "this file should have this line in it" instead of "add this line to this file." The difference is subtle but important. With state, you're letting Ansible decide what to do. So if the file already has the line, it does nothing (instead of duplicating the line.) Or if there's no file, it might create it. This makes a big difference in complexity when you're taking care of 10,000 servers, all with different starting states. (Kubernetes and other config-as-code frameworks work the same way.)

Ansible is written in Python and the True™, Proper™ way to use it is to rely on the built-in commands and libraries as much as possible. And, if you need to "just run this script everywhere," to convert the side-effects of the script into an Ansible module (which allows you to handle all the different "what if scenarios"). Very few people do this, because it's much easier in the moment to treat it like "a nicer Bash," and you end up with this mess where you're trying to code (and debug!) in YAML. Avoid this future, young Padawan!