How to write a Ansible Playbook to launch Websites Over Containers.

Abhishek Sahu
3 min readMar 18, 2021

Hello Readers, Today I am going to show you that, How Can you write a Ansible Playbook such that it will launch website for you over a docker container. Before Showing you the playbook, Let me introduce you to the key terms.

Ansible is a configuration management tool used to manage configuration of system. It is based upon Python Interpreter and maintained by RedHat.

Docker is a container software, developed and used for easy shipment of code. Now days It is also using for launching application on top of it as it provides a different environment for you.

Now there is a lot theory for now, Lets start implementing and building our own playbook.

Step 1:- Launch minimum two instances with SSH connectivity on both and install ansible on any one node. Installing is very simple just use yum install ansible.

Step 2:- Now create a YAML file and write the following code into it.

Creating Playbook
Playbook preview

Here you can download the complete source code from my Github repo :-

Step 3:- Open the inventory and enter the IP of node on which you want to launch your website.

Step 4:- Create a sample web template in the same folder in which playbook is located and name it as index.html and store some information inside it.

Creating web template

Step 5:- Launch the playbook using

“ansible-playbook docker.yml”

After the Playbook execution, You will see your webserver is launched with the content you put in the website.

Step 6:- Now enter the IP of node you wrote in playbook with port number 8080, you will see your website.

Entering IP
Launched Webpage

Thanks for reading this blog, Hope you find it helpful.

Reach me at LinkedIN —



Abhishek Sahu

Hey Readers, I am tech enthusiast and an Computer Science Student. Here I am sharing various industry use cases and its solution.