Referencing multiple hosts in an included task

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

“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?

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?