Configuring a Webserver on the Top of Docker Using Ansible

Adarsha Dinda
4 min readApr 9, 2021

Let’s see how we can configure an Apache Web Server on the top of Docker in any managed node with help of the Redhat Automation tool Ansible.

Redhat Ansible

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intra-service orchestration, and provisioning. Automation is crucial these days, with IT environments that are too complex and often need to scale too quickly for system administrators and developers to keep up if they had to do everything manually.

Apache Web Server

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.

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.

Now hopefully you have an idea about the above-mentioned tools and why they are very useful in the DevOps World. So Now let’s see which steps we have to follow to configure this setup that is mentioned in the problem statement.

Problem Statement

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

  1. Configure Docker.
  2. Start and enable Docker services.
  3. Pull the httpd(Apache) server image from the Docker Hub.
  4. Run the docker container and expose it to the public.
  5. Copy the html code in /var/www/html directory and start the webserver.

Note: I am setting up all the environments on the AWS Redhat Instance but you can set up this at any operating system i.e virtual machine (VM) Bare metal as well as a container.

Hopefully, now you have clear what we are going to perform. So let’s see one by one all the steps and what are the pre-requirements to set up the webserver in the docker container using ansible.

Now in this blog we will know how to launch our containers using Ansible and then we start to deploy our websites on Docker and expose it to public.

From the controller node, we need to configure Managed node and install docker there, for these we need to make a repository in which we keep our docker’s downloading URL. Since I have only two managed node, we can write all or managed node’s IP in hosts section.

*Now follow these steps in the Controller Node -

1- Check the version of the ansible installed in Controller node with the command “ansible — version”

2- Check the inventory file.

3- Check the configuration file of Ansible.

4.To check the connection with the managed node, we use: “ansible all -m ping”

5. Create a docker.yml file for playbook and write following commands :

6.Run the AnsiblePlaybook by using the command-

OUTPUT will be -

Now, the container is successfully created and configured as the webserver. Let’s access the webpage…

Manage nodes is working properly ……. that’s the power of Ansible…

🔹 Thanks for reading … 🔹

🔹 keep sharing 🔹

--

--