Difficulty: Intermediate
Estimated Time: 15-20 minutes

Please Read!

Your development environment is being prepared behind the scenes, so don't rush. Take advantage of the time you've been allotted and feel free to ask questions as you move through the tutorial.

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, just like you would in real life!


Let us summarize, what we have achieved so far:

  • We have prepared a successful connection from an Ansible host machine 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. This is an idealistic example, but the basis

Next: Ansible-First Playbook

Ansible-Getting Started

Step 1 of 7

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:

1. Connect to the Ansible container:

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

2. 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.

3. 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 the following:

CONTAINER ID      IMAGE                                   COMMAND                 CREATED         STATUS        PORTS NAMES
c96e3a45e164      ubuntu:14.04                            "/bin/bash -c 'whi..."  11 seconds ago  Up 9 seconds  target
caf61a258abb      virtuant/ansible-host-node:lte    "/bin/bash -c 'whi..."  13 seconds ago  Up 11 seconds ansible

This should take no longer than 30 sec. Continue to run docker ps to verify.

Note: Do NOT move on until you have verified your Ansible and Target containers are running.