Configuration of Apache WebServer on the Top Of Docker using Ansible

Image for post
Image for post

After reading This Article, You will be able to configure Webserver on the top of Docker using Ansible.

So without any further delay, Let’s get started.

What is Ansible?

Image for post
Image for post

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.

Let’s have a look at some of the terminology used in Ansible:

  1. Controller Node: Machine where Ansible is installed.
  2. Managed Node:Managed nodes are also sometimes called hosts.
  3. Inventory: Information regarding servers to be managed
  4. Playbook: Automation is defined using tasks defined in YAML format
  5. Task: Procedure to be executed
  6. Module: Predefined commands executed directly on remote hosts.

What is Docker ?

Image for post
Image for post

Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.

This Article contains the following tasks:

🎇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.

  • The system that you want to make Control Node install Ansible in it using command pip3 install ansible, then install openssh using command yum install openssh.
  • Now after installing ansible, just check using ansible — version command.
Image for post
Image for post
  • Now It is clear that Ansible is installed perfectly.
  • After installing Ansible create an Inventory anywhere in the system, here I have created an inventory named ip.txt
  • Now we have to provide details of managed node in this file created. Here I am Using RHEL8 Os as my Managed Node.
Image for post
Image for post
  • Here, 192.168.0.113 is IP of Managed Node
  • ansible_ssh_user : User you want to login in managed node
  • ansible_ssh_pass: provide the password of the above user
  • Now check the connectivity with Managed Node using the command ansible all -m ping
Image for post
Image for post
  • If it shows a message in green color that means there is connectivity and you will see the message ping pong.
  • For running ansible command, we need inventory file which is expected to be at a specified path: “/etc/ansible/hosts”. We can change its path using ansible config file (ansible.cfg file) in ansible workspace and define inventory file path there.
Image for post
Image for post
  • Now create yml file, here i have created file name docker.yml. This yml file is playbook where we write code in YAML.
  • The code in playbook is as below:
Image for post
Image for post
Image for post
Image for post
  • Now run the playbook using the command ansible-playbook docker.yml
Image for post
Image for post
  • Here, If we see green color then it means that much code is skipped, if we orange then some changes are made and if we don’t see any red color in output then it means The playbook is executed successfully.
  • Now we can verify that docker is installed in Managed Node.
Image for post
Image for post
  • Also Docker repo created in /etc/yum.repos.d
Image for post
Image for post
  • We can also see that container is launched.
Image for post
Image for post
  • Now check IP of the container.
Image for post
Image for post
  • Docker service also started
Image for post
Image for post

Now finally So the webpage is working well and showing the content properly whatever I write in the index.html file..

Image for post
Image for post

Voila, We did It🎇🎇

I hope you got an idea about how to configure webserver on the top of docker using Ansible. If you have any problem with the playbook then you check in the Github repository.

Thank You So Much For Reading😊

MACHINE LEARNING AND DATA SCIENCE ENTHUSIAST | ENTHUSIASTIC READER.

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