---
- hosts: localhost
  connection: local
  gather_facts: no
  become: no
  vars_files:
  - vars/main.yaml
  roles:
  # Group systems
  - instance-groups
  - cfn-outputs

- hosts: new_nodes
  gather_facts: yes
  become: yes
  vars_files:
  - vars/main.yaml
  roles:
  - non-atomic-docker-storage-setup
  - openshift-versions

- include: ../../../playbooks/add-node-prerequisite.yaml

- include: node-setup.yaml

- hosts: single_master
  gather_facts: yes
  become: yes
  vars_files:
  - vars/main.yaml
  roles:
  - ../../../roles/router-scaleup
  - ../../../roles/registry-scaleup

- hosts: localhost
  connection: local
  gather_facts: no
  become: no
  vars_files:
  - vars/main.yaml
  post_tasks:
  - name: add instance to ELB if node is infra
    ec2_elb:
      instance_id: "{{ hostvars[item].ec2_id }}"
      ec2_elbs: "{{ stack['ansible_facts']['cloudformation'][stack_name]['stack_outputs']['InfraLb'] | default(infra_elb_name) }}"
      region: "{{ region }}"
      wait: no
      state: present
    with_items: "{{ groups['tag_provision_node'] }}"
    when: node_type == "infra"

  - name: tag a resource
    ec2_tag:
      region: "{{ region }}"
      resource: "{{ hostvars[item].ec2_id }}"
      state: absent
      tags:
        provision: node
    with_items: "{{ groups['tag_provision_node'] }}"

- hosts: cluster_hosts
  gather_facts: yes
  become: yes
  vars_files:
  - vars/main.yaml
  roles:
  - gluster-ports
