Difficulty: Beginner
Estimated Time: 10 minutes

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.

Ansible Bootstrapping (Cannot remove Steps 3-6)

Step 1 of 10

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.