---
# Creates an EC2 instance to be the ansible master

- name: fetch build variables
  include_vars: "{{ item }}"
  with_items:
    - ../../vars/secrets.yml
    - ../../vars/shared.yml

- name: create an ubuntu instance
  ec2:
    region: "{{ ec2_region }}"
    image: "{{ ec2_base_image }}"
    instance_type: t2.micro
    key_name: "{{ ec2_provision_key }}"
    vpc_subnet_id: "{{ ec2_subnet_id }}"
    group: "{{ ec2_security_group }}"
    instance_tags:
      Ansible: Master
      Name: "{{ ec2_name_prefix }}-master"
    exact_count: 1
    count_tag:
      Ansible: Master
    wait: yes
    assign_public_ip: yes
  register: ec2_provision_result

- name: add it to the tag_Ansible_Master group here
  add_host: hostname={{ item.public_ip }} groups=tag_Ansible_Master
  with_items: "{{ ec2_provision_result.instances }}"

- name: wait for ssh to come up
  wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started
  with_items: "{{ ec2_provision_result.instances }}"

...

---
# Creates an EC2 instance to be the ansible master

- name: fetch build variables
  include_vars: "{{ item }}"
  with_items:
    - ../../vars/secrets.yml
    - ../../vars/shared.yml

- name: create an ubuntu instance
  ec2:
    region: "{{ ec2_region }}"
    image: "{{ ec2_base_image }}"
    instance_type: t2.micro
    key_name: "{{ ec2_provision_key }}"
    vpc_subnet_id: "{{ ec2_subnet_id }}"
    group: "{{ ec2_security_group }}"
    instance_tags:
      Ansible: Master
      Name: "{{ ec2_name_prefix }}-master"
    exact_count: 1
    count_tag:
      Ansible: Master
    wait: yes
    assign_public_ip: yes
  register: ec2_provision_result

- name: add it to the tag_Ansible_Master group here
  add_host: hostname={{ item.public_ip }} groups=tag_Ansible_Master
  with_items: "{{ ec2_provision_result.instances }}"

- name: wait for ssh to come up
  wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started
  with_items: "{{ ec2_provision_result.instances }}"

- debug:
    msg: new master instance is {{ item.public_dns_name }}
  with_items: "{{ ec2_provision_result.instances }}"

...

Add a debug message so we know the public dns for the newly created master instance
Add a debug message so we know the public dns for the newly created master instance
