Public | Automated Build

Last pushed: 2 years ago
Short Description
Ansible runner container for provision docker host from inside container
Full Description


This container allows you to provision a machine running docker via ansible running inside a container. This works by creating a temporary SSH key inside the container, adding it to the authorized_keys on the host and then performing a remote ansible play against localhost.

To Run:

Quick One-liner:

docker run -it --rm --net host -v [host ssh key dir]:/hostssh -v [host playbook dir]:[mounted playbook dir] pp2l/ansible-runner [ansible args]

Quick Example:

docker run -it --rm --net host -v ~/.ssh:/hostssh -v /my/playbooks/:/provisioning pp2l/ansible-runner /playbooks/provision.yaml

Longer answer

To run this, there are a few things you must pass to this container...

  • The SSH config directory of the user Ansible will connect via. This is needed to enable Ansible to connect back to the host machine by inserting a key into the authorized_keys file. This directory must be mounted at /hostssh inside the container. By default, Ansible will connect to the host machine as root. You can override this by specifying an ANSIBLE_USER environment variable.

  • The Anisble playbook directory. You can pass this in two ways:

    • Mount a directory from the docker host into the container at the mount point /provisioning
    • Pass a GIT url and optionally a GIT commit/branch to the container using the GIT_URL and GIT_COMMIT environment variables respectively.
  • The docker parameter --net host. This ensures that localhost inside the container is the actually host machine.

  • Some ansible arguments.. Pass the standard ansible-playbook arguments you would normally use to run your playbook at the end of the docker run command.


TODO: Put some more realistic examples here!

Run a set of playbooks stored on the host:

docker run docker run -it --rm --net host -v ~/.ssh:/hostssh -v /my/playbooks/:/provisioning pp2l/ansible-runner /provisioning/provision.yaml

Run a set of playbooks stored in GIT:

docker run docker run -it --rm --net host -v ~/.ssh:/hostssh -e GIT_URL="" -e GIT_COMMIT="my_branch" pp2l/ansible-runner /provisioning/provision.yaml

** NOTE: This will assume that the remote repo is public, keys are a WIP!

Docker Pull Command
Source Repository