How to configure ansible dynamic inventory on AWS
In this topic, we will discuss how to configure ansible dynamic inventory on EC2 AWS.
For that, you should download two files:
- ec2.ini – configuration file where you can specify some properties.
- ec2.py – python script that using boto3 for discovering.
We’ll modify an ec2.ini file because this file contains properties that we need to specify and edit (for example, specify a region or some resources like RDS).
- For starting you should have ansible installed on your system. Then just copy these two files in some folder, for example in /etc/ansible/.
- Your instance or local machine should have permissions to execute code and permissions to list objects in AWS
How you can check if all works. Execute this command
You should get output with ec2 instances grouped by tags, availability zones, instance types etc. And now you should be able to run ansible with and use ec2.py script as your hosts file.
ansible -i /etc/ansible/ec2.py -u ec2-user -m ping YOUR_TAG_NAME