- Ansible 2 Cloud Automation Cookbook
- Aditya Patawari Vikas Aggarwal
- 203字
- 2021-06-24 18:43:40
Deploying the phonebook application
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 a new instance without adding anything manually anywhere. Or we can use dynamic inventory, where we query the API of the cloud provider and build an in-memory inventory every time. For this chapter, we are going to look at using the add_host module and discuss the dynamic inventory in the next chapter.