---
- name: ovn-kubernetes | include global vars for minions
  include_vars: "{{ansible_tmp_dir}}/generated_global_vars.yml"
  when: not master

- name: ovn-kubernetes | include vars
  include_vars: "{{ ansible_distribution|lower }}.yml"

- name: ovn-kubernetes | Checking if binaries are already present on ansible machine
  local_action: stat path="{{ansible_tmp_dir}}/{{item}}"
  register: stat_bins_exists
  with_items:
    - "{{ovn_kubernetes_binaries.linux}}"
    - "{{ovn_kubernetes_binaries.windows}}"

- name: ovn-kubernetes | Expecting all binaries to be already present
  set_fact:
    binaries_missing: false

- name: ovn-kubernetes | Checking all binaries
  set_fact:
    binaries_missing: true
  with_items:
    - "{{stat_bins_exists.results}}"
  loop_control:
    label: "{{item.item}}"
  when: not item.stat.exists

- debug:
    msg: "Binaries are missing: {{binaries_missing}}"

- name: ovn-kubernetes | Build and install binaries
  include_tasks: ./build_install_bins.yml
  when: binaries_missing or master or not distribute_binaries

- name: ovn-kubernetes | Fetching Linux and Windows binaries
  include_tasks: ./fetch_bins.yml
  when: binaries_missing

- name: ovn-kubernetes | Distributing binaries to minion
  include_tasks: ./distribute_bins.yml
  when: minion and distribute_binaries
