Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration


Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating system kernel and therefore use fewer resources than virtual machines.

Now you must have got a basic idea about what ansible and docker is. In this story I’ll demonstrate how to launch webserver on Docker container using ansible. This can be done in a few ways but I’ll demonstrate the following:

  1. Directly interact with Docker daemon and launch the webserver.

  2. Use Kubernetes to launch the same on docker.

**This story does not cover installation of ansible on the controller node.


  1. Ansible installed and configured.

  2. Kubernetes Cluster(I have used minikube for this story).


Direct interaction with the docker daemon

1. First we have to specify the hosts(The hosts should have been already added to the inventory of ansible configuration file) where the tasks have to be carried out.

- hosts: worker

In my case the hosts have been grouped under worker in the inventory. I have configured only 1 node for this task but multiple ones can be configured to do the same.

2. I have used a bunch of variables as it gives it flexibility.

  - pname: "docker-ce-18.09.1-3.el7.x86_64"
    default_container_name: webserver
    default_container_image: httpd:latest

Now I shall specify the tasks