Create an Ansible playbook that will retrieve newContainer IP and update the inventory. So that further Configuration of Webserver could be done inside that Container.

Shivani Mandloi
3 min readJan 31, 2021

--

Description

Ceating a Ansible Playbook that will

🔹 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

🔹 Retrieve new Container IP and update the inventory

🔹 Installing httpd in container and starting service.

Here, We have to create a Playbook such that it will start and enable docker service , run a docker container and the same playbook will retrieve the newly launched container Ip , update it to the inventory and install httpd service.

here, I have to store a container name in variable that we will need while creating container .

Created Docker repo and installed docker-ce but we install docker from python library i.e. docker-py, thus installing python3

Coping Html file in container in root directory var/www/html.

and created a container with the accepted container name in cont_name earlier.

Remember that docker containers are not exposed thus its important to mention exposed_ports: port 80 (for webserver)

Saving container information in container_info variable using register using which we will retrieve IP to copy in inventory.

container_info[‘container’][‘NetworkSettings’][‘IPAddress’] variable will get Ip of launched container.

Now, setting up webserver over launched container, for which we need to install httpd in container and start service.

Now, Running playbook

you can check Your inventory file

Now, checking our webapp.

Thankyou so much hope you all find it interesting ..!!!

--

--

No responses yet