Configuring Apache Web Server on Docker Using Ansible

Monil Goyal
3 min readDec 29, 2020

In this article, I will tell you how to configure and start web-server using ansible-playbook.

Task Description

🔰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 docker container and expose it to the public
🔹 Copy the Html code in /var/www/html directory
and start the webserver

First of all, we have to update the inventory with the IP of the managed node.

In my case, The Managed node is rhel8. The IP of the managed node is 192.168.43.50

Update Inventory

Create Workspace

Create Playbook

Steps to create playbook:

Step 1: Write the IP of the target node in the host keyword

Step 2: Insert the variables

Step 3: Task to Configure Yum to install docker

Step 4: Task to Install Docker

Step 5: Task to Install Python interpreter

Step 6: Task to Install the docker library

Step 7: Task to Start Docker Service

Step 8: Task to create a directory in the target node to mount on a container.

Step 9: Task to copy the file from the controller node to targeted node

Step 10: Task to Pull httpd server image from docker hub

Step 11: Task to Run docker container

Thank you for reading…

--

--