Ansible and Docker : (An Automation UseCase)
Ansible playbook which Fetch IP of a new Container and dynamically update into the inventory with Configuring web-server inside new Docker Container
Problem Statement📄
We have to create an Ansible playbook that will retrieve IP of every new Container that is launched and update that IP in the Ansible inventory. So that we can host a Webserver inside that Container.
so Lets Begin
For this Problem statement I have used my own pre-created docker image which is enabled with ssh. So that Ansible can use ssh protocol to login to new docker container and configure webserver inside it.
In thiscase I am having Controller Node having IP 192.168.43.155 on which the ansible is installed
Lets check the ansible version installed on my controller node :
Initially inventory file is empty
Configuration file of ansible :
Ansible Playbook :
dockerip.txt file
task14.2-html file
Let’s run the main Playbook:
Inventory file dynamically updated
Checking whether Docker Service started and enabled:
Successfully Launched docker container with name myweb:
Now we can run our docker-web.yml playbook to configure webserver inside container:
Done! Now checking by Attaching to myweb container:
Now the webserver has been deployed on the docker container with the help of the Ansible Automation tool. So Let’s check our webpage from the browser :
Thank you for reading the article!!