# Cannot aggregate hosts after using ec2 module and with\_items

**URL:** <https://forum.ansible.com/t/cannot-aggregate-hosts-after-using-ec2-module-and-with-items/13244>\
**Category:** Ansible Project\
**Created:** [August 1, 2013, 9:47pm UTC](https://forum.ansible.com/t/cannot-aggregate-hosts-after-using-ec2-module-and-with-items/13244 "2013-08-01T21:47:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik\_Bakstad](https://avatars.discourse-cdn.com/v4/letter/e/a6a055/32.png) [@Erik\_Bakstad](https://forum.ansible.com/u/Erik_Bakstad)\
**Post date:** [August 1, 2013, 9:47pm UTC](https://forum.ansible.com/t/cannot-aggregate-hosts-after-using-ec2-module-and-with-items/13244/1 "2013-08-01T21:47:42Z")

</div>

I’m trying to figure out how to create multiple ec2 instances using with\_items so that I can control the id etc. The example under works, but I can’t figure out how to add the new server with add\_host.

- name: provision instance  
local\_action:  
module: ec2  
region: eu-west-1  
id: $item  
keypair: ${keypair}  
image: ${image}  
type: ${instance\_type}  
group\_id: ${security-group}  
vpc\_subnet\_id: ${subnet-id}  
register: instres  
with\_items:  
[web-1, web-2, web-3]

I’m trying something like this, but it doesn’t work.

- name: Register in inventory  
local\_action: add\_host name={{ $item.instances[0].private\_ip }} groupname=${group-identifier}  
with\_items:  
${instres.results}

Could someone please help me with the add\_host part?

Best regards

Erik
