# Getting a handle of ec2-instances

**URL:** <https://forum.ansible.com/t/getting-a-handle-of-ec2-instances/18458>\
**Category:** Ansible Project\
**Created:** [June 10, 2015, 7:08am UTC](https://forum.ansible.com/t/getting-a-handle-of-ec2-instances/18458 "2015-06-10T07:08:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yasser\_Hussain](https://avatars.discourse-cdn.com/v4/letter/y/f475e1/32.png) [@Yasser\_Hussain](https://forum.ansible.com/u/Yasser_Hussain)\
**Post date:** [June 10, 2015, 7:08am UTC](https://forum.ansible.com/t/getting-a-handle-of-ec2-instances/18458/1 "2015-06-10T07:08:30Z")

</div>

I have provisioned an amazon instance using ec2 module. Now I need to do some more manipulation on the instance. So does ansible get a handle on the instance it just created?

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [June 10, 2015, 2:54pm UTC](https://forum.ansible.com/t/getting-a-handle-of-ec2-instances/18458/2 "2015-06-10T14:54:46Z")

</div>

Hi,

Hope these links help.

[http://docs.ansible.com/guide\_aws.html](http://docs.ansible.com/guide_aws.html)

[https://github.com/ansible/ansible-examples/blob/master/language\_features/eucalyptus-ec2.yml](https://github.com/ansible/ansible-examples/blob/master/language_features/eucalyptus-ec2.yml)

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 10, 2015, 2:54pm UTC](https://forum.ansible.com/t/getting-a-handle-of-ec2-instances/18458/3 "2015-06-10T14:54:49Z")

</div>

You should be able to register a var which will get return info from  
the module, I believe this includes new instance ids.

---

<div class="post-metadata">

**Author:** ![Jakub\_Muszynski](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@Jakub\_Muszynski](https://forum.ansible.com/u/Jakub_Muszynski)\
**Post date:** [June 11, 2015, 12:19pm UTC](https://forum.ansible.com/t/getting-a-handle-of-ec2-instances/18458/4 "2015-06-11T12:19:33Z")

</div>

A quick example

- hosts: localhost  
connection: local  
gather\_facts: False

tasks:

- name: Provision a set of instances  
ec2:  
region: eu-central-1  
key\_name: some\_aws\_key  
group: default  
instance\_type: t2.micro  
image: ami-accff2b1

vpc\_subnet\_id: subnet-xxxxxxx

wait: yes

exact\_count: 3  
count\_tag:  
Name: Demo  
instance\_tags:  
Name: Demo  
test\_tag: Demo  
register: ec2\_ip: yes

i - debug: var=ec2

- name: Add instances to host group  
local\_action: add\_host hostname={{ item.public\_ip }} groupname=my\_group  
with\_items: ec2.instances

- name: Add tag to instances  
local\_action: ec2\_tag resource={{ item.id }} region=eu-central-1 state=present  
with\_items: ec2.instances  
args:  
tags:  
Name: EP2

- name: Add tag to instances  
local\_action: ec2\_tag resource={{ item.id }} region=eu-central-1 state=present  
with\_items: ec2.instances  
args:  
tags:  
Name: EP2

W dniu środa, 10 czerwca 2015 16:54:53 UTC+2 użytkownik Brian Coca napisał:
