title: Creating an aws target group with ansible
body: <p>What Im trying to accomplish is to create a network load balancer target group from dynamically generated list of instances.</p>
  
  <p>brokerInstancesList is a list of instance ids. I need to iterate over this list and add them as targets to this target group.</p>
  
  <pre><code>- name: "Create 9092 target group"
    elb_target_group:
      name: "tg-{{ ClusterName }}"
      protocol: tcp
      port: 9092
      vpc_id: "{{ VPCID }}"
      targets:
        - Id: "{{ item }}"
          Port: 9092
      state: present
    loop: "{{ brokerInstancesList }}"
  </code></pre>
  
  <p>The issue with my attempt above is that only the last entry in the brokerInstancesList is kept. Something like the below is what I need.</p>
  
  <pre><code>- name: "Create 9092 target group"
    elb_target_group:
      name: "tg-{{ ClusterName }}"
      protocol: tcp
      port: 9092
      vpc_id: "{{ VPCID }}"
      targets:
        {% for item in {{ brokerInstancesList }} -%}
        - Id: "{{ apple }}"
          Port: 9092
        {%- endfor %}
      state: present
  </code></pre>