Ansible-Playbook for Launching HTTPD over Docker

Aman Goyal
2 min readMar 26, 2021

Objective :- 🔰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

First we will provide ip details and inventory file

ip.txt
Providing Details of Inventory file to configuration file

Now what we need to do is to write playbook . In playbook first we will write code for configuring yum repo and installing docker software and enable docker services. Then we will put Httpd server image to Docker container and put a webpage there to show on website and finally we will expose our container to the world so that it get connectivity to internet.

Here is the Github repo link for code .

Finally run the Ansible Playbook

ansible-playbook docker.yml

Check the launched server by ip:port

That’s how we launch a webserver inside docker using Ansible-Playbook

That’s all with this article. I hope you found the post Informative, if something was missing or you think some more things could have been added, feel free to provide suggestions in the comments section.

You can check out my LinkedIn profile.

Thanks for giving your precious time to this article✌ Hope you like it .

--

--