Ansible Playbook to configure Docker


Ansible is powerful IT automation that you can learn quickly. It is simple enough for everyone in your IT team to use, yet powerful enough to automate even the most complex deployments.

Ansible Architecture is designed in such a way which uses some intelligence kind of thing and knows how to do, we only need to specify what to do.

Ansible can be used in 2 ways for configuration management:
1. Ad-hoc
2. PlayBook

🔹 Configure Docker

🔹 Start and enable Docker services

🔹 Pull the httpd server image from the Docker Hub

🔹 Run the docker container and expose it to the public

🔹 Copy the html code in /var/www/html directory and start the web server

IP of CN

IP of MN

Checking whether Ansible is installed or not:
ansible — version

Creating inventory:

Updating the ansible configuration file:

Checking the hosts, and connectivity to the hosts:

Creating a Play Book:

# vim dock_conf.yml

Executing PlayBook:

Let’s verify the Managed node:

Checking docker yum repo configuration

2. Checking Docker installation and services:

3. Checking the docker pulled image and checking whether the container is launched or not:

4. Port checking:

The docker named webserver1 is successfully launched in MN.

5. Going inside docker container to verify further things:

6. Checking the container webserver1 IP:

Our webserver is deployed successfully, now check the webpage:




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium


What does being a software tester mean to you?

Parking Space

Heroku Integration Capabilities: The Mini Guide

Database(PostgreSQL) browser with Talend ESB

Five Steps To Make Your First App

Swipe Detection in Unity

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aakash Bhardwaj

Aakash Bhardwaj

More from Medium

Jenkins Vs Teamcity CI Tool

How to Dockerize an Application[Step-By-Step]

Setup GitLab runner on AWS-ec2

Configure a local Jenkins instance