---
- name: fetch the security groups for launch config
  ec2_group_facts:
    filters:
      group-name: "{{ openshift_aws_launch_config_security_groups[openshift_aws_node_group.group] }}"
      vpc-id: "{{ vpcout.vpcs[0].id }}"
    region: "{{ openshift_aws_region }}"
  register: ec2sgs

- fail:
    msg: >
      "Unable to fetch expected security groups: {{ openshift_aws_launch_config_security_groups[openshift_aws_node_group.group] }}"
  when:
  - (ec2sgs.security_groups | map(attribute='group_name') | list | sort) != (openshift_aws_launch_config_security_groups[openshift_aws_node_group.group] | sort)

# Create the scale group config
- name: Create the node scale group launch config
  ec2_lc:
    name: "{{ openshift_aws_node_group.name }}-{{ openshift_aws_ami_map[openshift_aws_node_group.group] | default(openshift_aws_ami) }}-{{ l_epoch_time }}"
    region: "{{ openshift_aws_region }}"
    image_id: "{{ openshift_aws_ami_map[openshift_aws_node_group.group] | default(openshift_aws_ami) }}"
    instance_type: "{{ l_node_group_config[openshift_aws_node_group.group].instance_type }}"
    security_groups: "{{ openshift_aws_launch_config_security_group_id  | default(ec2sgs.security_groups | map(attribute='group_id')| list) }}"
    instance_profile_name: "{{ l_node_group_config[openshift_aws_node_group.group].iam_role if l_node_group_config[openshift_aws_node_group.group].iam_role is defined and
                                                                           l_node_group_config[openshift_aws_node_group.group].iam_role != '' and
                                                                           openshift_aws_create_iam_role
                                                                        else omit }}"
    user_data: "{{ lookup('template', 'user_data.j2') }}"
    key_name: "{{ openshift_aws_ssh_key_name }}"
    ebs_optimized: False
    volumes: "{{ l_node_group_config[openshift_aws_node_group.group].volumes }}"
    assign_public_ip: True
