---
# input variables:
# - openshift_service_type
# - openshift_is_containerized
# - openshift.common.hostname
# - openshift.master.api_port

# NOTE: This is needed to make sure we are using the correct set
#       of systemd unit files. The RPMs lay down defaults but
#       the install/upgrade may override them in /etc/systemd/system/.
# NOTE: We don't use the systemd module as some versions of the module
#       require a service to be part of the call.
- name: Reload systemd to ensure latest unit files
  command: systemctl daemon-reload

- name: Restart support services
  service:
    name: "{{ item }}"
    state: restarted
    enabled: True
  with_items:
    - NetworkManager
    - dnsmasq

- name: Restart container runtime
  service:
    name: "{{ openshift_docker_service_name }}"
    state: started
  register: docker_start_result
  until: not (docker_start_result is failed)
  retries: 3
  delay: 30

- name: Restart cri-o
  service:
    name: cri-o
    state: started
    enabled: true
  when: openshift_use_crio | bool

- name: Configure and start openvswitch systemd unit
  include_tasks: openvswitch.yml
  when: openshift_node_use_openshift_sdn | bool

- name: Start services
  service: name={{ item }} state=started
  with_items:
    - etcd_container
    - "{{ openshift_service_type }}-master-api"
    - "{{ openshift_service_type }}-master-controllers"
    - "{{ openshift_service_type }}-node"
  failed_when: false

- name: Wait for master API to come back online
  wait_for:
    host: "{{ openshift.common.hostname }}"
    state: started
    delay: 10
    port: "{{ openshift.master.api_port }}"
    timeout: 600
  when: inventory_hostname in groups.oo_masters_to_config
