Automation Using Ansible

What is Ansible

Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.

Ansible is the simplest way to automate apps and IT infrastructure. Application Deployment + Configuration Management + Continuous Delivery.

What is Docker

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.


Write an Ansible PlayBook that does the following operations in the managed nodes :

🔹 Configure Docker

🔹 Start and enable Docker services

🔹 Pull the httpd server image from the Docker Hub

🔹 Run the httpd container and expose it to the public

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


In this following problem statement we will integrate Docker with Ansible. And that Docker container has a Web Server on which we deploy a website. For solving this use case we have to follow some steps and all the steps must be done by using ansible play.

STEP 1: In this step I will configure my Ansible so that they can get connected to managed nodes.

Connect Managed nodes to Controller Node
Configure Ansible to detect Managed Nodes
Check Ansible Configuration
Check Connectivity

STEP 2:In this step I will check the managed nodes such that it don’t have docker repository and docker installed in it.


STEP 3:In this step I will create a task1_playcode directory which contain the playbook code for this task.

STEP 4:In this step I will start writing the plays for each & every step that is mentioned in problem statement & that file will be in YAML format

Filename = dockercode.yml

In this play we write one play which copies a sample web page code from my system to docker container.

Web Page
YML Code

STEP 5:In this step I will run this playbook file by following command:

ansible-playbook dockercode.yml

Playbook Output

STEP 6:In this step I will check the managed node and observe that now it has:

docker repo,

Docker-ce insatlled,

Webserver image pulled i.e. ashwani2399/webserver:v1

One conatiner is running

Web Server Image
Running Container

STEP 7:This is the final step & in this step we will check the output from the outside world.And we can access the web page from outside world because we had implemented the PAT concept.

GitHub URL: Click Here

LinkedIn Profile : Click Here

Feel Free to ask me any queries.