Ansible integration with docker and launch apache web server

🔰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

Ansible

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows

Unlike most configuration-management software, Ansible does not require a single controlling machine where orchestration begins. Ansible works against multiple systems in your infrastructure by selecting portions of Ansible’s inventory, stored as edit-able, version-able ASCII text files. Not only is this inventory configurable, but you can also use multiple inventory files at the same time and pull inventory from dynamic or cloud sources or different formats (YAML, INI, etc). Any machine with Ansible utilities installed can leverage a set of files/directories to orchestrate other nodes. The absence of a central-server requirement greatly simplifies disaster-recovery planning. Nodes are managed by this controlling machine — typically over SSH. The controlling machine describes the location of nodes through its inventory.Sensitive data can be stored in encrypted files using Ansible Vault.

Lets start setup part,

Step 1 : Configuration of docker

Let our target node is Rhel8 and to configure doker in rhel we need to first configure yum repository and install the software

Step-2: Start and enable Docker services

step 3: Pull the httpd server image from the Docker Hub

To pull the images from docker hub we need some requirements

  • python >= 2.6
  • docker-py >= 1.7.0
  • Docker API >= 1.20

Steps:

🔹 Run the docker container and expose it to the public
🔹 Copy the html code in /var/www/html directory
and start the web server

Now after complete playbook run the playbook

# ansible-playbook docker-cfg.yml

Now you can check we launch the complete docker container using ansible which is also expose to the port no. as mentioned in the playbook

code link:

https://github.com/Backbencher05/ansible-docker-apache.git

Thank you ,

feel free to ask any query

--

--

--

Arth2020 | student

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

Recommended from Medium

25 New Things Every Python Engineer Should Know in 2020

Build and Deploy a secure REST API with Go, Postgresql, JWT and GORM

Numpy Statistical Functions

Introduction to Python fundamentals for Data Science

Import.io Vs. Proxies API

ADDING TWO NUMBERS

Exp. Share | What does the tester need to do for performance testing? (1)

Uber SQL Interview Questions

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
Backbencher05

Backbencher05

Arth2020 | student

More from Medium

Part 5. Authentication with Open API 3.0

Automating Deploy WordPress with MySQL on Kubernetes cluster on AWS.

Initial Server Setup with Ubuntu 20.04

AWS Tutorial: Deploy an EC2 Instance