Setup AWS-EC2 Instance Management with Ansible in 10 commands

In our previous article we showed how to set up a postgresql server on a remote machine using Ansible. In this post, we show how to manage ec2 instances, in 10 commands with Ansible.

1. sudo pip install ansible, create ansible.cfg and host file

2. curl -O

3. curl -O

4. export ANSIBLE_HOSTS=~/Path_to_file/

5. export EC2_INI_PATH=~/Path_to_file/ec2.ini

6. export AWS_ACCESS_KEY_ID="*********"

7. export AWS_SECRET_ACCESS_KEY="**********"

8. ssh-agent bash

9. ssh-add ~/Path_to_key_File/yourkey.pem

10. python ~/Path_to_file/ --list

Currently, I have one instance running, and the list shows the same to me.


You can try, the launch more like this command in the EC2 console, run the above command, and test the result for yourself. The settings to tweak the results are located in ec2.ini, play around with it for different results.

Write custom playbooks, and run them against these machines!