---
- name: Master Install Checkpoint Start
  hosts: all
  gather_facts: false
  tasks:
  - name: Set Master install 'In Progress'
    run_once: true
    set_stats:
      data:
        installer_phase_master:
          title: "Master Install"
          playbook: "playbooks/openshift-master/config.yml"
          status: "In Progress"
          start: "{{ lookup('pipe', 'date +%Y%m%d%H%M%SZ') }}"

- name: Disable excluders and gather facts
  hosts: oo_masters_to_config
  roles:
  - openshift_facts
  tasks:
  - name: Disable excluders
    import_role:
      name: openshift_excluder
    vars:
      r_openshift_excluder_action: disable

  - openshift_facts:
      role: master
      system_facts: "{{ vars_openshift_facts_system_facts }}"
      local_facts:
        api_port: "{{ openshift_master_api_port }}"
        api_url: "{{ openshift_master_api_url | default(None) }}"
        api_use_ssl: "{{ openshift_master_api_use_ssl | default(None) }}"
        controllers_port: "{{ openshift_master_controllers_port | default(None) }}"
        public_api_url: "{{ openshift_master_public_api_url | default(None) }}"
        cluster_hostname: "{{ openshift_master_cluster_hostname | default(None) }}"
        cluster_public_hostname: "{{ openshift_master_cluster_public_hostname | default(None) }}"
        console_path: "{{ openshift_master_console_path | default(None) }}"
        console_port: "{{ openshift_master_console_port | default(None) }}"
        console_url: "{{ openshift_master_console_url | default(None) }}"
        console_use_ssl: "{{ openshift_master_console_use_ssl | default(None) }}"
        public_console_url: "{{ openshift_master_public_console_url | default(None) }}"

- import_playbook: certificates.yml

- name: Generate or retrieve existing session secrets
  hosts: oo_first_master
  roles:
  - role: openshift_facts
  tasks:
  - import_role:
      name: openshift_control_plane
      tasks_from: generate_session_secrets.yml

- name: Configure masters
  hosts: oo_masters_to_config
  any_errors_fatal: true
  pre_tasks:
  - name: Prepare the bootstrap node config on masters for self-hosting
    import_role:
      name: openshift_node_group
      tasks_from: bootstrap.yml
  - name: Have the masters automatically pull their configuration
    import_role:
      name: openshift_node_group
      tasks_from: bootstrap_config.yml

  roles:
  - role: openshift_master_facts
  - role: openshift_cloud_provider
    when: openshift_cloudprovider_kind is defined
  - role: openshift_builddefaults
  - role: openshift_buildoverrides

  - role: openshift_control_plane
  - role: tuned
  - role: nuage_common
    when: openshift_use_nuage | default(false) | bool
  - role: nuage_ca
    when: openshift_use_nuage | default(false) | bool
  - role: nuage_master
    when: openshift_use_nuage | default(false) | bool
  - role: calico
    when: openshift_use_calico | default(false) | bool
  - role: nsx
    when:
    - openshift_use_nsx | default(false) | bool
    - inventory_hostname == groups.oo_first_master.0
  - role: aci
    when:
    - openshift_use_aci | default(false) | bool
  - role: contrail_master
    when: openshift_use_contrail | default(false) | bool
  tasks:
  - import_role:
      name: kuryr
      tasks_from: master.yaml
    when: openshift_use_kuryr | default(false) | bool

  - name: setup bootstrap settings
    import_tasks: tasks/enable_bootstrap.yml

  post_tasks:
  - name: Re-enable excluders
    import_role:
      name: openshift_excluder
    vars:
      r_openshift_excluder_action: enable

- name: Deploy the central bootstrap configuration
  hosts: oo_first_master
  gather_facts: no
  tasks:
  - name: setup bootstrap settings
    import_tasks: tasks/enable_bootstrap_config.yml
  - name: setup automatic node config reconcilation
    run_once: True
    import_role:
      name: openshift_node_group
      tasks_from: sync.yml

- name: Ensure inventory labels are assigned to masters
  hosts: oo_masters_to_config
  gather_facts: no
  roles:
  - role: openshift_manage_node
    openshift_master_host: "{{ groups.oo_first_master.0 }}"
    openshift_manage_node_is_master: "{{ ('oo_masters_to_config' in group_names) | bool }}"
    openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"

- name: Master Install Checkpoint End
  hosts: all
  gather_facts: false
  tasks:
  - name: Set Master install 'Complete'
    run_once: true
    set_stats:
      data:
        installer_phase_master:
          status: "Complete"
          end: "{{ lookup('pipe', 'date +%Y%m%d%H%M%SZ') }}"
