Configuration of apache webserver on the top of docker container with the help of ansible playbook

Before jumping to the integration part of ansible and docker , let’s first begin with

What is 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. Automation simplifies complex tasks, not just making developers’ jobs more manageable but allowing them to focus attention on other tasks that add value to an organization. In other words, it frees up time and increases efficiency. And Ansible, as noted above, is rapidly rising to the top in the world of automation tools. Let’s look at some of the reasons for Ansible’s popularity.

How to Use Ansible With Docker?

First, let’s talk about what docker is?

Docker is a Linux-based open-source platform used to help automate the deployment of applications within software containers. (A container is a unit of software in which code and all of its dependencies are packaged together; setting up software this way helps an application run reliably and consistently in multiple computing environments.)

For integrating docker with ansible, let’s move to the installation part of Ansible:

Before installing ansible make sure your system has python because ansible built on top of python. So let’s check the python is there or not with the command —

python3 — version

If in case you don’t have python then follow the command to install python in RHEL8

yum install python3

After Installing python successfully

Now to connect to target nodes ansible by-default use SSH protocol. To enable SSH protocol in controller node we need two packages which is epel-release and sshpass. First we need to install epel-release package which will configure yum and gave us extra packages with sshpass. Run below commands to install these two packages

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -yyum install sshpass 

Now Install ansible using the following command-

pip3 install ansible

We’ve successfully install ansible with version 2.10.3

Update the configuration file:

After installing ansible create an Inventory anywhere in the system, here I have created an inventory named ip.txt

Vocabulary that are used in inventory file name is ip.txt

  • ansible_ssh: User you want to login in managed node
  • ansible_ssh_pass: provide the password of the above user
  • ansible_connection: The medium of connection using this both are connecting to each other.

Now check the connectivity of managed node using the following command:

ansible all -m ping

If it shows a message in green color that means there is connectivity and we will see the message ping pong.

NOW WE WILL PERFORM THE TASK :

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.

Now create yml file, here docker.yml

A

Write the following code:

Before running the ansible-playbook, check the yum repository of docker

To check docker repo, go to the path

cd /etc/yum.repos.d/
docker repo not present

Now run the playbook using the following command —

ansible-playbook -v docker.yml

Now again check docker repository:

Now install docker:

Append the code -

Now run the code:

Check whether docker is installed or not, Use the following command in the managed node:

Docker services has not started, we can see it from below command:

Start docker services by appending the following code:

Run the yml file:

Check whether it started or not:

Now we have to launch docker image, we can see that there is no docker image in the managed node:

To launch docker image and copy the html file, append with the following code:

Run the playbook:

We don’t have any container running

docker container not running

To launch container append with the following code:

Run the yml file:

CONTAINER LAUNCHED!!

Now we’ll check webpage running or not with IP:port/<webpage name>

I hope you all got the idea about how to configure the webserver on the top of the docker using Ansible

Thank you!!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

SLAE #2: Shell Reverse TCP

How we messed up being one of the early Slack bots

Dart & Flutter

3 Free Mac Apps to Boost Your Productivity as Manager

Couchbase in multi kubernetes cluster environment — Option-2 Detailed (using Amazon VPC CNI and…

Detecting Market Regime With the Slope Indicator.

Java Reactive Programming — Cold Publisher vs Hot Publisher

Golang: Calling a nil struct function

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

suman15

More from Medium

Getting Started with Container Volumes and Persistent Storage

Overview of Microsoft Azure for creating a Website

How to Install Kubernetes on Windows 10?

What Is a Staging Environment and the Road to Optimized Deployment