title: Using Ansible to create AWS Application Load Balancer rules
body: <p>I'm trying to use Ansible to create rules for an unconfigured HTTP listener on my existing ALB. I kick things off by retrieving facts for the alb and then use those facts to define an Ansible ALB resource adding the rules I want, but I'm hitting an issue.</p>
  
  <p>I would like Ansible to loop through my group_vars file (which it already does for other tasks successfully) to create these multiple rules. However when looping through, instead of appending rules to the listener it destroys/creates them. So when the playbook completes you are just left with a single rule referencing whichever item is defined at the end of the vars file (in my case Surrey).</p>
  
  <p>My code is below (for the sake of brevity I have excluded the parts which get &amp; set facts):</p>
  
  <pre><code>- name: Add HTTP listener rules
    elb_application_lb:
      state: present
      name: "{{ albinfo.load_balancer_name }}"
      subnets:
        - "{{ albinfo.availability_zones[0].subnet_id }}"
        - "{{ albinfo.availability_zones[1].subnet_id }}"
        - "{{ albinfo.availability_zones[2].subnet_id }}"
      security_groups:
        - "{{ albinfo.security_groups[0] }}"
      listeners:
        - Protocol: HTTP
          Port: 80
          DefaultActions:
            - Type: forward
              TargetGroupName: default
          Rules:
            - Conditions:
                - Field: host-header
                  Values: "{{ item.url }}"
              Priority: "{{ item.priority }}"
              Actions:
                - TargetGroupName: "{{ item.name }}"
                  Type: forward
      purge_listeners: no
    with_items: "{{ regions }}"
  </code></pre>
  
  <p>And my "regions" vars file looks like this:</p>
  
  <pre><code>regions:
    - name: manchester
      priority: 1
      url:
        - manchester.example.com
  
    - name: surrey
      priority: 2
      url:
        - surrey.example.com
  </code></pre>