# Using register with exact\_count when launching an instance on EC2

**URL:** <https://forum.ansible.com/t/using-register-with-exact-count-when-launching-an-instance-on-ec2/15630>\
**Category:** Ansible Project\
**Created:** [July 9, 2014, 8:50am UTC](https://forum.ansible.com/t/using-register-with-exact-count-when-launching-an-instance-on-ec2/15630 "2014-07-09T08:50:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ofer\_Herman](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@Ofer\_Herman](https://forum.ansible.com/u/Ofer_Herman)\
**Post date:** [July 9, 2014, 8:50am UTC](https://forum.ansible.com/t/using-register-with-exact-count-when-launching-an-instance-on-ec2/15630/1 "2014-07-09T08:50:08Z")

</div>

Hi,

I’m using exact\_count when creating an instance on EC2, when the instance already exists the next action fails with the following error:

fatal: [localhost] =\> One or more undefined variables: ‘unicode object’ has no attribute ‘public\_ip’

This is the playbook:

- name: Provision EC2 SC instances  
local\_action:  
module: ec2  
region: “{{ aws\_region }}”  
keypair: “{{ aws\_keypair }}”  
group: ansibleDefault  
instance\_type: “{{ aws\_instanceType }}”  
image: “{{ aws\_image }}”  
exact\_count: 1  
count\_tag:  
Class: “websever”  
vpc\_subnet\_id: “{{ vpc.subnets[0].id }}”  
assign\_public\_ip: True  
instance\_tags: { “Class”:“webserver” }  
wait: yes  
register: ec2\_info

- name: Wait for SSH to come up  
local\_action: wait\_for host={{ item.public\_ip }} port=22 delay=60 timeout=320 state=started  
with\_items: ec2\_info.instances

How can the playbook continue even if the instance exist?

Thanks,  
Ofer

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [July 9, 2014, 3:03pm UTC](https://forum.ansible.com/t/using-register-with-exact-count-when-launching-an-instance-on-ec2/15630/2 "2014-07-09T15:03:39Z")

</div>

Try using debug on ec2\_info to see what it contains. It seems that  
instances is coming back with a list of strings and not a list of  
objects like you thought.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 9, 2014, 7:49pm UTC](https://forum.ansible.com/t/using-register-with-exact-count-when-launching-an-instance-on-ec2/15630/3 "2014-07-09T19:49:44Z")

</div>

For clarity, this:

- debug: var=ec2\_info

---

<div class="post-metadata">

**Author:** ![Stuart\_Reynolds](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Stuart\_Reynolds](https://forum.ansible.com/u/Stuart_Reynolds)\
**Post date:** [July 9, 2014, 9:47pm UTC](https://forum.ansible.com/t/using-register-with-exact-count-when-launching-an-instance-on-ec2/15630/4 "2014-07-09T21:47:30Z")

</div>

ec2\_info.tagged\_instances? Does that give all of the instances matching the tag, whether or not they we created in the prior step.  
Test with:

- debug: var=ec2\_info

---

<div class="post-metadata">

**Author:** ![Craig\_Marvelley](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@Craig\_Marvelley](https://forum.ansible.com/u/Craig_Marvelley)\
**Post date:** [November 11, 2015, 11:43am UTC](https://forum.ansible.com/t/using-register-with-exact-count-when-launching-an-instance-on-ec2/15630/5 "2015-11-11T11:43:45Z")

</div>

Was a solution ever found for this problem? Have the same problem where sometimes the ec2 module launches instances and sometimes it doesn’t, but I want to work with the data of the running instances regardless.
