Ansible is a configuration management tool, much like Puppet, Chef and CF Engine. It’s used to automate the configuration of servers and network devices. Although it benefits infrastructures of all sizes, tools like it are essential in agile data centers where you expect to do a lot of scale-out architectures. One of the main benefits of Ansible over other configuration management tools is that unlike most, it is agentless and, therefore, does not need to be tied down to a master server.

The benefit to being agentless is not having to install additional packages on to servers to manage them. Configurations are applied to a server locally or through an SSH tunnel. Since the tunnel uses a well known port that is probably already open anyways, there’s little need to involve your networking or security teams.

The goal of this posting is to introduce you to the basics of Ansible. I will guide you through configuring a simple web server on a Ubuntu server.

Installing Ansible

As mentioned above, it isn’t necessary to install Ansible on the system you plan on configuring. We can install it on our desktop or on another  server. It makes little difference, so long as their is network connectivity.

CentOS and Red Hat

Ansible is not includes in the default repositories for Red Hat and CentOS. To install it, you also need to install the EPEL repository.

  1. Install the EPEL repository onto your server.CentOS 6.X – 64-bit
    rpm -ivh

    CentOS 7.X – 64-bit

    rpm -ivh
  2. Install Ansible from EPEL.
    yum install ansible

Debian and Ubuntu

Unlike CentOS and Red Hat, Ansible is available in the Ubuntu package manager.

sudo apt-get install ansible


Ansible uses playbooks to apply configurations. With playbooks we can automate the configuration of a LAMP server by having it install PHP, MySQL and Apache for us. In the diagram below, we are using a single playbook file to configure multiple LAMP servers in an AWS environment.

Ansible Playbook Diagram

The following is an example of the playbook used in the diagram above. We target a group of servers and instruct Ansible to install the required packages.

The hosts value specifies the server or group of servers that the playbook will be applied to. Under tasks, you specify a name and then an action for every task that will be performed. Tasks are what will be used to install packages and do other configurations. The name is essential a brief description of the action about to be completed. The action is what the task will accomplish. In the example above, the actions are yum, which means we will be instructing Ansible to install a package.

Creating a Playbook

  1. To create a playbook, create a new file and give it the YAML extension (.yml). Make sure its name is descriptive so you can identify it easier later on.
  2. The first line of every playbook must start with three dashes (-). This is a YAML requirement. Without those dashes, Ansible will not parse the file properly.

Applying Playbooks

You can apply your playbook using the apply-playbook command. As it runs through your playbook, each task will appear with a status when completed. When all tasks have been processed, whether successfully or not, a summary will then be shown.

ansible-playbook local-lamp-server.yml

As the playbook is processed, you will

Ansible playbook output