Apache webserver configuration on top of docker using ansible

What is Ansible??
Ansible is an open-source software that automates software provisioning, configuration management, and application deployment.Ansible is included as part of the Fedora distribution of Linux, owned by Red Hat, and is also available for Red Hat Enterprise Linux, CentOS, openSUSE, SUSE Linux Enterprise, Debian, Ubuntu, Scientific Linux, and Oracle Linux via Extra Packages for Enterprise Linux (EPEL), as well as for other operating systems. Ansible is procedural rather than declarative. In ansible, we define what we want to do and ansible go through each and every step for that.Ansible uses SSH to connect to remote hosts and do the setup, no software needed to be installed beforehand on a remote host. It’s simple, powerful and flexible.
What is Apache webserver??
Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web. It’s widely thought that Apache gets its name from its development history and process of improvement through applied patches and modules but that was corrected back in 2000. It was revealed that the name originated from the respect of the Native American tribe for its resiliency and durability.
What is docker??
Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.
Use-case:
"🔰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 web server
"
Pre-requisite:
- Install ansible in the controller node.
In ansible the node which configures all the other computers/nodes is known as controller node and nodes getting configured are known as managed/target nodes
- Below playbook shows the entire configuration .


- First we have configured the yum repository for docker in the managed node.
- Then, in second task we have installed docker and then started the service of docker.
Below image shows that in managed node we have installed docker and started the service.

- Then install docker SDK which is necessary to download the container image.
- Now we have downloaded container image of httpd in further task.

Above image shows the image is loaded inside the managed/target node
- Now we have copied the file inside the /var/www/html/docker.html in the managed node with the specific content.
- Next, last task we have to run the container image in docker

This shows that the container has started running in the docker.
- We can run the ansible playbook by the below command.Below image gives the command along with output when we run the ansible playbook.


- We can now see inside the browser our web server configured and we get the content in the browser.

So ,TASK COMPLETED!!!
I hope you all will like my blog 😊✍️
Thanks in advance 👍