- hosts: localhost
  connection: local
  gather_facts: false
  become: false
  vars:
    cluster_state: running
    cluster_region: us-west-2
    instance_type: t2.medium
    aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
    aws_secret_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
    ec2_pod_spec:
      key: "{{ aws_keyname }}"
      cluster_name: "{{ cluster_id }}"
      rules:

        - proto: tcp # ssh
          from_port: 22
          to_port: 22
          cidr_ip: 0.0.0.0/0

        - proto: all
          group_name: "ec2_pod_{{cluster_id}}"
          group_desc: "Ec2 security group for cluster {{ cluster_id }}"

      hosts:
        head:
          type: "{{ master_instance_type }}"
          image: "{{ master_instance_ami}}"

        data:
          type: "{{ node_instance_type }}"
          count: "{{ node_instance_count }}"
          image: "{{ node_instance_ami}}"
  roles:
    - role: ec2-pod
      default_ssh_key: "{{ ec2_pod_spec.key }}"
      # passed in from deployment script
      cluster_name: "{{ ec2_pod_spec.cluster_name }}"
      state: "{{ cluster_state }}"
      region: "{{ cluster_region }}"
      default_image: ami-e0f7e081
      rules: "{{ ec2_pod_spec.rules }}"
      hosts: "{{ ec2_pod_spec.hosts }}"

- hosts: localhost
  connection: local
  gather_facts: false
  become: false
  vars:
    cluster_state: running
    cluster_region: us-west-2
    instance_type: t2.medium
    aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
    aws_secret_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
    ec2_pod_spec:
      key: "{{ aws_keyname }}"
      cluster_name: "{{ cluster_id }}"
      rules:

        - proto: tcp # ssh
          from_port: 22
          to_port: 22
          cidr_ip: "{{ source_cidr_ip |default('0.0.0.0/0') }}"

        - proto: all
          group_name: "ec2_pod_{{cluster_id}}"
          group_desc: "Ec2 security group for cluster {{ cluster_id }}"

      hosts:
        head:
          type: "{{ master_instance_type }}"
          image: "{{ master_instance_ami}}"

        data:
          type: "{{ node_instance_type }}"
          count: "{{ node_instance_count }}"
          image: "{{ node_instance_ami}}"
  roles:
    - role: ec2-pod
      default_ssh_key: "{{ ec2_pod_spec.key }}"
      # passed in from deployment script
      cluster_name: "{{ ec2_pod_spec.cluster_name }}"
      state: "{{ cluster_state }}"
      region: "{{ cluster_region }}"
      default_image: ami-e0f7e081
      rules: "{{ ec2_pod_spec.rules }}"
      hosts: "{{ ec2_pod_spec.hosts }}"

Allow the source IP for incoming requests to be specified
Allow the source IP for incoming requests to be specified
