Difficulty: beginner
Estimated Time: 15 minutes

Ansible is a modern IT automation tool that uses SSH to connect to its targets.

Ansible is a relatively new member of a larger family of IT automation tools. This InfoWorld article from 2013 compares Puppet, Chef, Ansible and Salt.

In this tutorial, we will learn, how to prepare a target system, so an Ansible system can connect to it.


Let us summarize, what we have achieved so far:

We have prepared the successful connection from an Ansible system to a target system by

  1. installing an ssh server on the target
  2. creating an SSH key pair on the Ansible system
  3. copying the public key of the Ansible host to the target system

We have tested the connection by using an Ansible "ping", which is an SSH connection from the Ansible host to the target, actually.

Further Reading:

For more information about Ansible, see also following blogs on Ansible:

Posts of this series:

  1. Ansible Hello World: Getting started with Playbooks and Inventories
    • with a comparison of Ansible vs. Salt vs. Chef vs. Puppet and a hello world example with focus on Playbooks (i.e. tasks), Inventories (i.e. groups of targets) and remote shell script execution.
  2. Ansible Hello World: Templating
  3. Ansible Hello World: Graphical User Interface "Ansible Tower"

You might also be interested in this Salt Hello World: Getting started with States and Node Groups

Ansible Bootstrapping

Step 1 of 7

Step 1 - Prepare Environment for easier Toggling between Ansible and Target System

To make our lives easier later, let us define the commands "a" and "t" for quickly connecting from the base system to the ansible and target container:

Connect to the Ansible container:

a() { docker exec -it ansible bash -c "echo 'PS1='\''ansible# '\' >> /root/.bashrc; bash"; }

Connect to the Target container:

t() { docker exec -it target bash -c "echo 'PS1='\''target# '\' >> /root/.bashrc; bash"; }

In this tutorial, we already have started an ansible and a target container in the background. However, they have been started in the background, and they need some time to become available. Repeat using a docker ps command to check, whether Docker containers named 'ansible' and 'target' have been started already:

docker ps

Repeat sending the command until it looks similar to

CONTAINER ID      IMAGE                                   COMMAND                 CREATED         STATUS
            PORTS NAMES
c96e3a45e164      ubuntu:14.04                            "/bin/bash -c 'whi..."  11 seconds ago  Up 9 seconds target
caf61a258abb      williamyeh/ansible:ubuntu14.04-onbuild  "/bin/bash -c 'whi..."  13 seconds ago  Up 11 seconds ansible

This should take no longer than 30 sec.