Hi All,

I have an application load balancer in AWS with an HTTP listener configured 
(another tool provisioned it, not ansible). Anyway my task is to add rules 
to its HTTP listener using Ansible by looping through a vars file.

I first use Ansible's various AWS get_fact operations to discover the load 
balancer, it's ARNs, subnetIDs etc. Then I define the load balancer using 
Ansible's elb_application_lb module and use the facts I've previously 
retrieved to set the properties for it's name, security groups etc. All of 
this works beautifully well.

Then under the HTTP listener properties, I define one rule using the 
"with_items" feature. My hope would be that it'd loop through my list, 
creating the rules I want (and it does kind of do this..), however instead 
of appending the rules to the listener as it goes, it instead deletes the 
existing rule then creates the next one. So when the playbook completes I'm 
left with the ALB with just one listener rule defined (and it will be 
whichever entry is last in my vars file). The code is below:

- name: Add HTTP listener rules
    state: present
    name: "{{ albinfo.load_balancer_name }}"
      - "{{ albinfo.availability_zones[0].subnet_id }}"
      - "{{ albinfo.availability_zones[1].subnet_id }}"
      - "{{ albinfo.availability_zones[2].subnet_id }}"
      - "{{ albinfo.security_groups[0] }}"
      - Protocol: HTTP
        Port: 80
          - Type: forward
            TargetGroupName: test
          - Conditions:
              - Field: host-header
                Values: "{{ item.url }}"
            ListenerArn: "{{ albinfo.listeners[0].listener_arn }}"
            Priority: "{{ item.priority }}"
              - TargetGroupName: "{{ item.name }}"
                Type: forward
    purge_listeners: no
  with_items: "{{ regions }}"

And my "regions" var file looks like this:

  - name: manchester
    priority: 1
      - manchester.dev.noglet.panlogic.co.uk

  - name: surrey
    priority: 2
      - surrey.dev.noglet.panlogic.co.uk

I'm sure that this is a logic error on my part and not a bug, so could 
anybody explain where I'm going wrong?

You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to