I was first introduced to Ansible a little over a year ago and it’s changed my sysadmin life. It is hands down the best way to manage and deploy servers, but its flexibility lends it to being used for an almost infinite number of tasks. It even does Windows.
Before Ansible, I did my sysadmin work using a lot of
bash mixed with a little
kickstart and some
imaging. Ansible combined with virtualization has replaced those tools and is much easier to work with and maintain. It’s fairly trivial to convert existing shell scripts into Ansible playbooks that are idempotent (more on that later). Playbooks written in YAML syntax are so easy to read relative to shell scripts they are practically self-documenting. Ansible uses the Jinja2 templating language for creating templates, a powerful and intuitive way to create fairly complex files. Ansible does everything over SSH without the need to install an agent. It’s like magic, and the best kind.
Roles in Ansible provide a convenient way to group tasks and other files in a way that makes them easy to share and reuse. You can pass variables to a role when it is called from a playbook to make its output different or have it run different tasks. Ansible Galaxy provides a central hub for sharing and downloading roles. It’s a great place to look for common server configurations like MySQL or SSH.
My favorite feature in Ansible is idempontency. That is a fancy way of saying Ansible only makes changes if the change hasn’t already been made. As someone who spent countless hours writing tests in
bash before running a regexp with
sed, and being bit when my regexp got applied many times to the same file, this built-in feature of Ansible is a godsend. When I write tasks in Ansible, I am asserting that “this is the way it should be”. Ansible will then do what it needs to do in order to make my assertions match reality.
If you’re interested in taking your sysadmin skills to the next level with Ansible, the best place to start is with the official docs. If you’re looking for a more guided tour with some great practical examples, I highly recommend Ansible for DevOps by Jeff Geerling. That is where I learned about YAML’s multi-line syntax as well as some other neat Ansible tricks. His GitHub repositories are a treasure trove of great Ansible examples.
There is also an O’Reilly book coming soon titled Ansible Up & Running by Lorin Hochstein. Ansible has hit the big time!