Read http://www.ansible.com/blog/ansible-ec2-tags It details how to spin up an ec2 instance (or multiple) and then run tasks against it (I.e install nginx).
I'f you want to jump straight to the example playbook https://github.com/chrismeyersfsu/playbook-ec2_properties/blob/master/new_group.yml
- Bring up ec2 instance
- Wait for ssh
- add ec2 instance to Ansible dynamically created host group w/ associated ec2 pem file (so you can ssh to it)
- Call an example play with a ping task to show everything works
Note: you would replace the ping task with your set of tasks to install nginx
@Bidyut How to reference ec2 ip address
look at Line 27 Note the use of register: ec2
Then at Line 46 the ec2 ip address is "extracted" {{ ec2.results[item.0]['instances'][0]['public_ip'] }}
. Note that the example calls register
within a loop. If you are just creating one ec2 instance then the ec2 ip address reference would look like {{ ec2.results['instances'][0]['public_ip'] }}