Apache WebServer Configuration in Docker using Ansible

What is Ansible?

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice 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.

What is Docker?

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files. All containers are run by a single operating system kernel and therefore use fewer resources than virtual machines.

Ansible Architecture

Ansible Playbooks :

Ordered lists of tasks, saved so you can run those tasks in that order repeatedly. Playbooks are written in YAML format.

Inventory :

A list of managed nodes. An inventory file is also sometimes called a hostfile . Your inventory can specify information like IP address for each managed node.

Control Node:

Any machine with Ansible installed is known as controller node. You can run Ansible commands and playbooks by invoking the ansible or ansible-playbook command from any control node.

Managed Node:

The network devices (and/or servers) you manage with Ansible. Managed nodes are also sometimes called hosts .

Task Description:

  • 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

Steps :

Install ansible in controller mode

pip3 install ansible
yum install sshpass
#To see version of ansible installed
ansible --version

List of Managed Nodes in the inventory file

vim /ip.txt
  • is IP of Managed Node
  • ansible_ssh_user : Username of managed node
  • ansible_ssh_pass: password of managed node

Ansible Configuration File

vim /etc/ansible/ansible.conf

To view all Managed Nodes connected

ansible all --list-hosts

To check connectivity with all Managed Nodes

ansible all -m ping


vim docker_setup.yml

Link to Code

Run playbook

ansible-playbook docker_setup.yml

Check docker is configured and services are started in Managed Node

docker --versionsystemctl status docker

Check container is launched

docker ps

Open the link in browser

I’m an undergraduate student at IIIT Ranchi, pursuing my B-Tech in Electronics and Communication Engineering.

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