An Ansible Tutorial

Ansible is a configuration management and provisioning tool, similar to Chef, Puppet or Salt.

I’ve found it to be one of the simplest and the easiest to get started with. A lot of this is because it’s “just SSH”; It uses SSH to connect to servers and run the configured Tasks.

One nice thing about Ansible is that it’s very easy to convert bash scripts (still a popular way to accomplish configuration management) into Ansible Tasks. Since it’s primarily SSH based, it’s not hard to see why this might be the case – Ansible ends up running the same commands.

We could just script our own provisioners, but Ansible is much cleaner because it automates the process of getting context before running Tasks. With this context, Ansible is able to handle most edge cases – the kind we usually take care of with longer and increasingly complex scripts.

Ansible Tasks are idempotent. Without a lot of extra coding, bash scripts are usually not safety run again and again. Ansible uses “Facts”, which is system and environment information it gathers (“context”) before running Tasks.

Ansible uses these facts to check state and see if it needs to change anything in order to get the desired outcome. This makes it safe to run Ansible Tasks against a server over and over again.

Here I’ll show how easy it is to get started with Anible. We’ll start basic and then add in more features as we improve upon our configurations.

Job search with resume and job application on computer work table background

Install

Of course we need to start by installing Ansible. Tasks can be run off of any machine Ansible is installed on.

This means there’s usually a “central” server running Ansible commands, although there’s nothing particularly special about what server Ansible is installed on. Ansible is “agentless” – there’s no central agent(s) running. We can even run Ansible from any server; I often run Tasks from my laptop.

Here’s how to install Ansible on Ubuntu 14.04. We’ll use the easy-to-remember ppa:ansible/ansible repository as per the official docs.

  1. sudo apt-add-repository -y ppa:ansible/ansible
  2. sudo apt-get update
  3. sudo apt-get install -y ansible

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *