add_host in ansible

Hi All,
I am very new to ansible. Just started learning about it.Got stuck in module “add_host” .
Went through docs but it didn’t helped me much.So ,i request anyone to help me with sample example.
Thanks in advance.

hello,
The add_host module makes use of variables to create an in-memory inventory of new hosts and groups that can be used in subsequent plays within the same playbook.

Normally Ansible requires an inventory file to be created to know which machines it is meant to operate on.

This is typically a manual process but can be greatly improved by using the likes of the dynamic inventory to pull inventory information from other systems.

Suppose, you needed to create 40 number of instances which were transient in nature and had no existing details available to populate an inventory file for Ansible to utilise? If you have small number of instances you could easily hand-craft the inventory file but once this number gets into tens of instances it becomes difficult.
To solve this problem we can use the add_host module, with information it generates while creating new instances.