This blog is a demonstration of the configuration of the Docker container in such a way that the container IP is dynamically updated in an Inventory of a Controller Node.
So Let's get started...
What is Ansible and Docker?
- Head over to this link 👉 https://dev.to/niteshthapliyal/apache-webserver-configuration-in-docker-using-ansible-1dde
Now we know what Ansible and Docker are so, let's get started with the demonstration...
First create an Inventory file
Create an Inventory file with an extension
.txt, here I have created an Inventory file named
ip.txt. We don't need to add the IP address of the Target node in that as it will be dynamically updated.
Create Ansible Configuration file
To create an ansible file, create a file with extension
.cfg, here I have a configuration file with named
Now create an Ansible Playbook
Create an Ansible playbook with an extension
.yml, here I have created a playbook named
This playbook will configure Docker, install docker, pull Docker image, and then fetch the Ip of the container and updated it in an inventory of the controller node.
Now run the Playbook
To run the playbook use command
Playbook ran successfully!!!✨
Now check that is IP updated in an Inventory of a Controller Node
Earlier we have seen that Ip.txt[ Inventory file] was empty👇
After running the playbook👇
Now we can see that IP is updated!!✨
So that's how we can configure the docker container in such a way that the IP of the container is updated dynamically to an Inventory of Controller Node.