🔺Ansible Playbook to Retrieve Docker container IP and Update in Inventory using customized SSH enabled Docker Image and Host a Webserver.🔺

Hi guys,

In this blog i will show how to Create an Ansible Playbook that will retrieve the IP of newly launched Docker Container and update it in the Inventory file and also launch a Webserver on top of it using Ansible Playbook.

For this I have created my own customized centos image for enabling ssh inside a docker container and uploaded in docker hub click here to check it.

I have created the image using Docker file

create a file named [Dockerfile] and enter the code below .

vim /root/Dockerfile

◾ In the above code i have used centos image to install net-tools, openssh-server and passwd software.

◾ Generated a Key and Run sshd Service in background.

Now Build it

Above u can see Image Created .

Now lets configure Ansible.

/etc/ansible/ansible.cfg

Now lets create a Ansible Playbook that does the following things

  • Install docker
  • Start docker service
  • Pull Image & launch container & expose the docker container
  • Retrieve docker container IP
  • Inside inventory mentioning docker container IP for further web server configuration.
/ansible/task14–2.yml

Now lets Run the PLaybook

# ansible-playbook task14–2.yml

Above U can see Docker Container has successfully launched.

Inventory File BEFORE

Inventory File AFTER running playbook

docker group has been added

Successfully It has Retrieved the ip of Newly Launched container…

Now lets launch a Webserver On top of it

For that lets Create a Playbook for it

vim /ansible/httpd.yml

now lets run the playbook

Playbook successfully launched .

Lets check weather it is working or not

YES u can see our Webserver successfully Launched on top of a Docker Container

By this we have Successfully Done our task.

YOU can access code at GitHub:

Thats all For now I hope it helped you… if any queries feel free reach me at Linkidin.

--

--

--

Passionate learner || Data Science Enthusiast || Django || Competitive Programmer

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

Recommended from Medium

Kotlin and the rise of Multiplatform

Cassandra with docker in a native way!.

Docker Best Practices: Images

Experience of Creating A Full WVD Golden Image

Determining ROI for Your RPA Project

Starting Game Development with Unity3D!

5 Ways to Clone An Object in C#

Substitute your Finder 27.21 relay with the Shelly 1 WiFi switch

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
Dileepkumar

Dileepkumar

Passionate learner || Data Science Enthusiast || Django || Competitive Programmer

More from Medium

Simple way to add SSH on Bitbucket ☑️

How to run any GUI software on the container ?

OpenAPI Tools by OxygenXML

Setting up an SSH Key for your containers using docker compose