Hi There,
Seems like the code is executing the entire block twice, ie the ELB 
creation is getting executed twice.
Here is the reference document: 
http://docs.ansible.com/ansible/latest/playbooks_loops.html

--------------------------------------------------------------------------

- name: add several users
  user:
    name: "{{ item }}"
    state: present
    groups: "wheel"
  with_items:
     - testuser1
     - testuser2

is equivalent to:

- name: add user testuser1
  user:
    name: "testuser1"
    state: present
    groups: "wheel"- name: add user testuser2
  user:
    name: "testuser2"
    state: present
    groups: "wheel"







On Sunday, 4 February 2018 09:59:15 UTC-5, geo...@divirted.com wrote:
>
> 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.example.com
>
>   - name: surrey
>     priority: 2
>     url:
>       - surrey.example.com
>
>
> 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 
https://groups.google.com/d/msgid/ansible-project/8bd2a400-9159-4514-8d81-eddcca83af69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to