- block:

  - name: set connection information for all tasks
    set_fact:
      aws_connection_info: &aws_connection_info
        aws_access_key: "{{ aws_access_key }}"
        aws_secret_key: "{{ aws_secret_key }}"
        security_token: "{{ security_token }}"
        region: "{{ aws_region }}"
    no_log: yes

  - name: create ALB with a listener
    elb_application_lb:
      name: "{{ alb_name }}"
      subnets: "{{ alb_subnets }}"
      security_groups: "{{ sec_group.group_id }}"
      state: present
      listeners:
        - Protocol: HTTP
          Port: 80
          DefaultActions:
            - Type: forward
              TargetGroupName: "{{ tg_name }}"
      <<: *aws_connection_info
    register: alb

  - assert:
      that:
        - alb.changed
        - alb.listeners|length == 1
        - alb.listeners[0].rules|length == 1

  - name: test idempotence creating ALB with a listener
    elb_application_lb:
      name: "{{ alb_name }}"
      subnets: "{{ alb_subnets }}"
      security_groups: "{{ sec_group.group_id }}"
      state: present
      listeners:
        - Protocol: HTTP
          Port: 80
          DefaultActions:
            - Type: forward
              TargetGroupName: "{{ tg_name }}"
      <<: *aws_connection_info
    register: alb

  - assert:
      that:
        - not alb.changed
        - alb.listeners|length == 1
        - alb.listeners[0].rules|length == 1
