# Referencing multiple hosts in an included task

**URL:** <https://forum.ansible.com/t/referencing-multiple-hosts-in-an-included-task/13678>\
**Category:** Ansible Project\
**Created:** [October 15, 2013, 8:53am UTC](https://forum.ansible.com/t/referencing-multiple-hosts-in-an-included-task/13678 "2013-10-15T08:53:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sundar1](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@Sundar1](https://forum.ansible.com/u/Sundar1)\
**Post date:** [October 15, 2013, 8:53am UTC](https://forum.ansible.com/t/referencing-multiple-hosts-in-an-included-task/13678/1 "2013-10-15T08:53:36Z")

</div>

Am just trying to do a scale up activity.

In the Scale up script, I refer the localhost from where I initiate / spawn new ec2 instances. Upon creating the ec2 instances I do multiple actions on few other servers (haproxy & a redis server).

From the Scale up script, I include a task wherein, I’m trying to add / allow the newly created instance ip to access redis server’s port.

**scaleup.yml**

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 15, 2013, 2:15pm UTC](https://forum.ansible.com/t/referencing-multiple-hosts-in-an-included-task/13678/2 "2013-10-15T14:15:03Z")

</div>

“What happens is, the inclusion sends all the servers in the group - prod\_webservers to the included tasks, (1.1.1.1, 2.2.2.2)”

What did you want to do instead?

---

<div class="post-metadata">

**Author:** ![Sundar1](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@Sundar1](https://forum.ansible.com/u/Sundar1)\
**Post date:** [October 17, 2013, 7:58am UTC](https://forum.ansible.com/t/referencing-multiple-hosts-in-an-included-task/13678/3 "2013-10-17T07:58:29Z")

</div>

I thought / wanted, it would pass one by one, like it does in other places. for instance,

- name: add / allow this instance in the firewall of Redis  
command: iptables -A INPUT -p tcp -s {{ NEW\_INSTANCE\_IP }} --dport 6379 -j ACCEPT  
delegate\_to: “{{ item }}”  
with\_items: groups.prod\_memory\_cache\_redis

The above code passes items one by one, I guess.

So I thought

- include: prod/tasks/redis\_firewall\_addition.yml NEW\_INSTANCE\_IP={{ item.public\_ip }}  
with\_items: ec2.instances

would also work like that - passing each item one by one to the task prod/tasks/redis\_firewall\_addition.yml.

Something that I misunderstood? If so, how can I accomplish this?
