🔺Ansible Playbook to Retrieve Docker container IP and Update in Inventory using customized SSH enabled Docker Image and Host a Webserver.🔺
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 .
◾ 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.
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.
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
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
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:
Contribute to dileep-hub/Ansible_Docker_IP_Retrieve_Webserver development by creating an account on GitHub.
Thats all For now I hope it helped you… if any queries feel free reach me at Linkidin.