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

In this task we have to create ansible playbook that will update inventory with the IP of new container that we are launching using same playbook.
Firstly we have to store container name in a variable that we will use while creating container in further task.
Created docker repo and installed docker-ce and then installed python3 because we have to install docker from python library i.e docker-py.

Copying html content file from root directory to var/www/html. Pulling httpd image and creating container using that image with name accepted in cont_name earlier.and important to mention exposed_ports: port 80 for webserver.
Saving container information in container_info variable using register that we will use to retrieve IP that will be further copied in inventory.

Using blockinfile module copying the block in inventory.
To get details container_info we can print it using debug.
container_info[‘container’][‘NetworkSettings’][‘IPAddress’] is location where we get ip of launched docker container.
Now, as we want to setup webserver in launched container we need to install httpd in container and start the service. So, giving docker as hosts, installing httpd and starting service.

Running playbook docker14.yml

Checked in inventory IP is updated with username, password and connection details in docker group -

Checking for the website with docker container IP

Thank you…😊✌