Our phonebook application can be deployed to the instances that we have created. When deploying an application to an instance, we either need to know the IP address of the instance and prepare the inventory, or we can figure out the IP address at runtime. Preparing the inventory is often simple, however, it requires manual intervention. We have to run tasks to boot an EC2 instance with the required parameters and copy the IP address of the instance to the inventory file. After this, we can run the playbook for deploying the application.
Manually adding IPs to the inventory is not possible for unattended setups. In certain cases, the infrastructure is dynamic to the extent that managing IPs might not even be possible. For such cases, there are two possibilities: we can use Ansible's add_host module to deploy an application when we boot up...