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
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: test
Rules:
- Conditions:
- Field: host-header
Values: "{{ item.url }}"
ListenerArn: "{{ albinfo.listeners[0].listener_arn }}"
Priority: "{{ item.priority }}"
Actions:
- TargetGroupName: "{{ item.name }}"
Type: forward
purge_listeners: no
with_items: "{{ regions }}"
And my "regions" var file looks like this:
regions:
- name: manchester
priority: 1
url:
- manchester.dev.noglet.panlogic.co.uk
- name: surrey
priority: 2
url:
- 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/3ed782cf-c736-4f4a-a3ee-b0e5a84c3933%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.