Create 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.

suman15
4 min readMay 30, 2021

TASK DESCRIPTION:

Further in ARTH — Task 10 have to create an Ansible playbook that will retrieve newContainer IP and update the inventory. So that further Configuration of Webserver could be done inside that Container.

TASK 10 reference:

LET’S START OUR PRACTICAL:

→ Make one Docker image, add user, configure the password, and enable ssh

You can build your own image or can use the below SSH enabled image:

📌Below is the process of creating your own image👇

Here we are going to use Dockerfile to create an SSH enabled image:

We need a ssh enabled image because by default ansible use ssh protocol to login inside any container or os and do configuration there.

Dockerfile

→ To build the image:

Now we have Dockerfile ready, it’s time to build the image

Use the below command to build

→ To change the tag :

Use the below command to change the tag

→ Now we are going to push the image to docker hub :

SSH enabled image has been created:

Let’s proceed further:

→ Create an ansible configuration file :

Note: Initially the inventory file is empty

→ Next create an Ansible Playbook for container setup and also it will auto update the inventory file:

In the above playbook we have used the blockinfile module for configuring inventory.

Check the syntax:

Lets Run the Playbook:

So, This playbook will setup the container and the inventory file

Output of the playbook:

Inventory file dynamically updated:

Docker container launched!!

We can verify from below commands

We can even cross-check using the #docker ps command

Now, let’s setup the webserver on the container:

Check the syntax by using below command:

Run the playbook:

Output of the playbook

After running this playbook we got :

Write the IP of the container to view your webpage created

We have successfully launched a container and retrieved and updated IP address using ansible playbook and also configured the webserver inside it.

Github link for your reference:

Thank You for Reading!!!!!😀

--

--