# Can't get returned IPs from EC2

**URL:** <https://forum.ansible.com/t/cant-get-returned-ips-from-ec2/15965>\
**Category:** Ansible Project\
**Created:** [August 15, 2014, 10:35pm UTC](https://forum.ansible.com/t/cant-get-returned-ips-from-ec2/15965 "2014-08-15T22:35:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Morgan](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Matthew\_Morgan](https://forum.ansible.com/u/Matthew_Morgan)\
**Post date:** [August 15, 2014, 10:35pm UTC](https://forum.ansible.com/t/cant-get-returned-ips-from-ec2/15965/1 "2014-08-15T22:35:14Z")

</div>

So, I’m super stuck on this problem. I created a pastie of all the info.

[http://pastie.org/private/po3yakcngchu8wzjiwhsa](http://pastie.org/private/po3yakcngchu8wzjiwhsa)

What am I doing wrong in the playbook that I can’t get those IPs into my hosts file?

Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [August 15, 2014, 10:56pm UTC](https://forum.ansible.com/t/cant-get-returned-ips-from-ec2/15965/2 "2014-08-15T22:56:23Z")

</div>

add\_host is for adding a host to current run’s in-memory inventory, not the one on disk. It’s used to provision a newly-created VMs. You want to either use dynamic inventory and pull data from EC2, or somehow add the host to static inventory (with lineinfile maybe?)

---

<div class="post-metadata">

**Author:** ![Matthew\_Morgan](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Matthew\_Morgan](https://forum.ansible.com/u/Matthew_Morgan)\
**Post date:** [August 16, 2014, 2:37am UTC](https://forum.ansible.com/t/cant-get-returned-ips-from-ec2/15965/3 "2014-08-16T02:37:27Z")

</div>

Okay, I understand that it only adds to the in-memory inventory, but that’s not really the problem I’m having.

The problem I’m having is I can’t get the IP. What I plan to do with the IP after I get it involves provisioning those hosts. I can’t provision those hosts unless I get the IP from the current run which creates the host.

The step where I should be able to get the IP to add it to a group (in memory or otherwise) is failing.

`

TASK: [Add new instance to host group] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost → 127.0.0.1] =\> One or more undefined variables: ‘str object’ has no attribute ‘tagged\_instances’

FATAL: all hosts have already failed – aborting

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [August 16, 2014, 7:20am UTC](https://forum.ansible.com/t/cant-get-returned-ips-from-ec2/15965/4 "2014-08-16T07:20:58Z")

</div>

Sorry, I only skimmed that paste and missed the actual problem. For the record: it’s easier if you paste examples in your mail, and it’s better for archiving too 🙂 is “run this task for all of ec2.results”, but what you wrote is “run this task for all of [‘ec2.results’]” (that’s why it’s complaining about a string). You want:

---

<div class="post-metadata">

**Author:** ![Matthew\_Morgan](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Matthew\_Morgan](https://forum.ansible.com/u/Matthew_Morgan)\
**Post date:** [August 17, 2014, 3:28am UTC](https://forum.ansible.com/t/cant-get-returned-ips-from-ec2/15965/5 "2014-08-17T03:28:26Z")

</div>

That was exactly my issue. Thank you very much for your help!
