---
- name: create core infrastructure
  hosts: localhost
  roles:
  - ssl-certificate
  - role: deployment-create
    deployment_name: core
  post_tasks:
  - name: wait for instance groups to be ready
    include_role:
      name: wait-for-instance-group
    with_items:
    - '{{ prefix }}-master'
    - '{{ prefix }}-node'
    - '{{ prefix }}-infra-node'
    loop_control:
      loop_var: instance_group
  - name: refresh gce inventory
    command: '{{ inventory_dir }}/gce/hosts/gce.py --refresh-cache'
    changed_when: false
  - meta: refresh_inventory

- name: continue with the core infrastructure deployment, after the instances are created
  hosts: localhost
  roles:
  - dns-records
  - ssh-proxy
  - role: wait-for-instance
    instance: '{{ hostvars[prefix + "-bastion"]["gce_public_ip"] }}'

- name: wait for all instances to accept ssh connections
  hosts: '{{ prefix }}-bastion'
  tasks:
  - name: wait for all instances
    include_role:
      name: wait-for-instance
    with_items: '{{ groups["tag_" + prefix] }}'
    loop_control:
      loop_var: instance
