Configure Webserver Inside the docker container with the help of ansible-playbook

Shubham Jangid
3 min readJan 6, 2021

🔰 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

👉 Pre requisites For this setup is:-

  1. Two system which have Rhel8 installed or “for perform this setup I use virtualization tool”
  2. Local dnf Configured in both system
  3. install python3 in One system which you want to make as “Controller Node”, for this you use CMD “dnf install python3 -y”
  4. install ansible package in controller node for this use CMD:- “pip3 install ansible -y”

👨‍💻 Lat’s start working on the setup:-

Step 1: First create an inventory file Where you put the IP and user name, user password and protocol for connectivity:-

Step 2: Create a configuration file for the ansible where you put the info about inventory file “vim /etc/ansible/ansible.cfg”

Here inventory=<path of your inventory file>

Step 3: Write ansible-playbook file (you can download from the my GitHub repository mentioned in blow)

Step 4: Check Connectivity with “Manage Node”

Step 5: Run ansible-playbook in Controller Node

here we use -vv for more verbosity
Configure dnf for docke-ce and install docker
start services of docker
install python3 and its library and pull docker image
install httpd and start services of httpd
Copy web pages
Open port for 8484

NOTE: here I’m not uploading all the images

YOUR ENTIRE SETUP IS READY

Step 6: Now Check Docker-ce install in controller node Or not

Step 7: Check services of docker started or not

Step 8: Check docker image is pulled or not

Step 9: Check port 8484 is enabled for docker or Not

Step 10: Check docker container started or not

here we can see port forwarding is enabled

Final Output :-

Thank You

--

--