Using dynamic inventory
In our previous recipes and the previous chapter, we have seen how easily we can create AWS resources. When running production loads on AWS Cloud, we tend to scale out and scale in the resources according to traffic and workloads. But with this dynamic nature of the cloud to scale in and out, managing a static inventory file for Ansible is an operational task and overhead, and it becomes really difficult if we want to implement features such as autoscaling.
With the help of dynamic inventory, we can solve this. Ansible provides an EC2 dynamic inventory script called ec2.py
(https://github.com/ansible/ansible/blob/devel/contrib/inventory/ec2.py).
How to do it...
- We will be running Ansible ad hoc commands using the EC2 dynamic inventory and shell module to execute
/bin/uname -a
:
ansible -i ec2.py tag_Name_my_first_instance -m shell -a "/bin/uname -a"
- Similarly, we can use the dynamic inventory to target the following specific features:
- Instance IDs
ansible -i ec2.py <instance...