To create amazon ec2 instances dynamically and to manage them I have followed the following instructions-I have chosen
Ubuntu 16.04 as my
ansible controller machine and will be using an ubuntu
AMI. I have also generated some credentials from amazon’s
IAM. Add the credentials into environment variables.
To get started with dynamic EC2 inventory management, we need to download 2 files.
EC2.ini. I have used
wget to get the files to my working directory.
if you have installed ansible via pip you might need to create a directory in
/etc directory called
ansible. I installed ansible via pip so I had to create the directory. Move these to files to
/etc/ansible/ directory. Please consider using
sudo if required.
Please remember to download the
ansible.cfg from ansible githubrepository and put it into same
So to use the dynamic inventory management script rather than the one provided with ansible (
/etc/ansible/hosts), again we need to set a variable
This tells the ansible in the control machine to look for
ec2.py rather than
hosts file. This
ec2.py requires another configuration file called
ec2.ini. You can put it in the same directory or you can define it manually at the top of
ec2.py script by opening it in a text editor. (if required) add