---

- name: Is istio.addon be iterable
  set_fact:
    is_istioaddon_iterable: "{{ istio.addon is defined and istio.addon is iterable }}"

- include_tasks: set_implicitly_disabled_addons.yml

- name: Determine addons that need ServiceAccounts
  set_fact:
    selected_addons_needing_sa: "{{ istio.addon | intersect(addons_needing_sa) | difference(disabled_addons) }}"
  when: is_istioaddon_iterable == true

- name: Set selected_addons_needing_sa to empty array
  set_fact:
    selected_addons_needing_sa: "[]"
  when: is_istioaddon_iterable == false

- include_tasks: set_appropriate_cmd_path.yml
  when: cmd_path is not defined

- name: Extract server version
  shell: |
    {{ cmd_path }} version | sed -En "{{'s/kubernetes.*v([[:digit:]]\.[[:digit:]]\.[[:digit:]]).*/\1/p' if cluster_flavour == 'ocp' else 's/Server Version.*GitVersion.*v([[:digit:]]\.[[:digit:]]\.[[:digit:]]).*/\1/p'}}" | head -1
  register: vo

- assert:
    that:
      - "vo.stdout >= minimum_cluster_version"
    msg: "Cluster version must be at least {{ minimum_cluster_version }}"

- include_tasks: assert_oc_admin.yml
  when: cluster_flavour == 'ocp'

- include_tasks: install_distro.yml
- include_tasks: delete_resources.yml
  when: istio.delete_resources == true
- include_tasks: safely_create_namespace.yml
  vars:
    ns_name: "{{ istio.namespace }}"
- include_tasks: change_scc.yml
  when: cluster_flavour == 'ocp'
- include_tasks: install_on_cluster.yml
- include_tasks: install_samples.yml
  when: (istio.samples is iterable) and (istio.samples | length > 0)