Retrieving new container IP and updating inventory

Retrieving new container IP and updating inventory

?? Task 14.2 ARTH - 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.

Github link->

It is always necessary to get the new container IP, when a new container is launched in docker, so that further configuration can be done.

We get the container IP by ansible facts.

No alt text provided for this image

here we use loops, as we have to configure the repos, in the same way.

What are hostvars in Ansible?

hostvars is a magical variable in Ansible. Variables related to Ansible are called magic variables.

The difficulty that we face here in this case is that we launch the container and register the IP variable. Now in order to save the IP variable we have to save it in inventory, which is in controller node. So if we write other play and try to access the registered variable from the first play, we get error as that variable is only for the first play.

In order to solve this we use hostvars.

No alt text provided for this image

lineinfile module -

  • This module ensures a particular line is in a file, or replace an existing line using a back-referenced regular expression.
  • This is primarily useful when you want to change a single line in a file only.

now run the playbook by

ansible-playbook playbook2.yml
No alt text provided for this image

Our webpage is deployed on the container, and we are able to access the page due to exposing the port.

No alt text provided for this image






















要查看或添加评论,请登录

Yash Indane的更多文章

  • Use of K-mean clustering in security domain

    Use of K-mean clustering in security domain

    Summer Task-10 & ARTH Task 42 Github -> What is K-means Clustering? K-means clustering is one of the simplest and…

  • OSPF Routing Protocol using Dijkastra Algorithm

    OSPF Routing Protocol using Dijkastra Algorithm

    What is OSPF? The OSPF (Open Shortest Path First) protocol is one of a family of IP Routing protocols, and is an…

  • Using Face Recognition for automation

    Using Face Recognition for automation

    SUMMER-TASK-6 (Team Task) and ARTH TASK 38 GitHub -> In this article I will explain how we can use Face Recognition and…

    3 条评论
  • JavaScript use cases in Industry

    JavaScript use cases in Industry

    Summer Task 7.2 What is JavaScript? JavaScript, often abbreviated as JS, is a programming language that conforms to the…

    1 条评论
  • Use of confusion matrix in detecting cyber crime

    Use of confusion matrix in detecting cyber crime

    Summer 2021 Task 05 ??????? Particularly in the last decade, Internet usage has been growing rapidly. However, as the…

  • Running Chrome in Docker container

    Running Chrome in Docker container

    Summer - Task 02 ??????? By default containers don't support GUI, but by some way we can achieve that, let's discuss…

    3 条评论
  • Training a ML model inside a container

    Training a ML model inside a container

    Task 01 ??????? Task Description ?? ?? Pull the Docker container image of CentOS image from DockerHub and create a new…

    4 条评论
  • Deploying WordPress in Amazon EKS with RDS in Backend

    Deploying WordPress in Amazon EKS with RDS in Backend

    ARTH-TASK-23 WordPress is a free and open-source content management system written in PHP and paired with a MySQL or…

    3 条评论
  • How industry uses MongoDB

    How industry uses MongoDB

    ARTH-TASK-32 What is MongoDB? MongoDB is a source-available cross-platform document-oriented database program…

  • Creating a Multicloud Setup of Kubernetes using Ansible Roles

    Creating a Multicloud Setup of Kubernetes using Ansible Roles

    TASK 28 Task Description ?? ?? CREATE A MULTI-CLOUD SETUP of K8S cluster: ?? Lunch node in AWS ?? Lunch node in Azure…

    2 条评论

社区洞察

其他会员也浏览了