Extracting inner (nested) elements from a list, or launching EC2 instances on more than one zone

Hello wise people of Ansible

An existing playbook I have launch EC instances as follow (simplify):

`

  • name: Launch instances
    local_action:
    module: ec2
    region: “{{region}}”
    instance_type: “{{instance_type}}”
    image: “{{image}}”
    count: “{{cluster_nodes}}”
    register: ec2_clusterEnter code here…
    `

I later use ec2_cluster as:

`

local_action: add_host name={{item.public_ip}} groupname=New
with_items: ec2_cluster.instances

`

Now, I need to launch instances on more than one zone, so I added a dictionary with all the variables, and use the same operation with
`
“with_dict: regions”

`

This works fine, but the ec2_cluster format has change. It have all the data as before, but the instances are nested in
ec2_cluster.results[0].instances,

ec2_cluster.results[1].instances

etc

My question (finally):
What is the idiomatic way to extract the public ip of all the instances from all the regions?

Thanks
Tzach

Answering my own question:

Good question Tzach :wink:
This is how you should do it:

`

local_action: add_host name={{item.1.public_ip}} groupname=NewDB
with_subelements:

  • ec2_cluster.results
  • instances

`

posting again with right Indentation

`

local_action: add_host name={{item.1.public_ip}} groupname=NewDB
with_subelements:

  • ec2_cluster.results
  • instances

`