---
- name: Create ELB ( master public )
  ec2_elb_lb:
    cross_az_load_balancing: "yes"
    health_check:
      ping_protocol: https
      ping_port: 443
      ping_path: "/api"
      response_timeout: 2
      interval: 5
      unhealthy_threshold: 2
      healthy_threshold: 3
    listeners:
      - protocol: tcp
        load_balancer_port: 443
        instance_protocol: tcp
        instance_port: 443
    name: "{{ clusterid }}-public-master"
    region: "{{ aws_region }}"
    scheme: internet-facing
    security_group_ids:
      - "{{ sg.results.0.group_id }}"
    state: present
    subnets:
      - "{{ subnet_public.results.0.subnet.id }}"
      - "{{ subnet_public.results.1.subnet.id }}"
      - "{{ subnet_public.results.2.subnet.id }}"
    tags:
      name: "{{ clusterid }}-public-master"
      Clusterid: "{{ clusterid }}"
    wait: true
  retries: 3
  delay: 3
  register: elbextmaster

- name: Create ELB ( master private )
  ec2_elb_lb:
    cross_az_load_balancing: "yes"
    health_check:
      ping_protocol: https
      ping_port: 443
      ping_path: "/api"
      response_timeout: 2
      interval: 5
      unhealthy_threshold: 2
      healthy_threshold: 3
    listeners:
      - protocol: tcp
        load_balancer_port: 443
        instance_protocol: tcp
        instance_port: 443
    name: "{{ clusterid }}-private-master"
    region: "{{ aws_region }}"
    scheme: internal
    security_group_ids:
      - "{{ sg.results.0.group_id }}"
    state: present
    subnets:
      - "{{ subnet_private.results.0.subnet.id }}"
      - "{{ subnet_private.results.1.subnet.id }}"
      - "{{ subnet_private.results.2.subnet.id }}"
    tags:
      name: "{{ clusterid }}-private-master"
      Clusterid: "{{ clusterid }}"
    wait: true
  retries: 3
  delay: 3
  register: elbintmaster

- name: Create ELB ( infra public )
  ec2_elb_lb:
    cross_az_load_balancing: "yes"
    health_check:
      ping_protocol: tcp
      ping_port: 443
      response_timeout: 2
      interval: 5
      unhealthy_threshold: 2
      healthy_threshold: 2
    listeners:
      - protocol: tcp
        load_balancer_port: 80
        instance_protocol: tcp
        instance_port: 80
      - protocol: tcp
        load_balancer_port: 443
        instance_protocol: tcp
        instance_port: 443
    name: "{{ clusterid }}-public-infra"
    region: "{{ aws_region }}"
    scheme: internet-facing
    security_group_ids:
      - "{{ sg.results.1.group_id }}"
    state: present
    subnets:
      - "{{ subnet_public.results.0.subnet.id }}"
      - "{{ subnet_public.results.1.subnet.id }}"
      - "{{ subnet_public.results.2.subnet.id }}"
    tags:
      name: "{{ clusterid }}-public-infra"
      Clusterid: "{{ clusterid }}"
    wait: true
  retries: 3
  delay: 3
  register: elbextinfra
