---
- name: Install clients
  package: name={{ openshift_service_type }}-clients{{ openshift_pkg_version | default('') }} state=present
  when: not openshift_is_containerized | bool
  register: result
  until: result is succeeded

- block:
  - name: Pull CLI Image
    command: >
      docker pull {{ openshift_cli_image }}:{{ openshift_image_tag }}
    register: pull_result
    changed_when: "'Downloaded newer image' in pull_result.stdout"

  # openshift_container_binary_sync is a custom module in lib_utils
  - name: Copy client binaries/symlinks out of CLI image for use on the host
    openshift_container_binary_sync:
      image: "{{ openshift_cli_image }}"
      tag: "{{ openshift_image_tag }}"
      backend: "docker"
  when:
  - openshift_is_containerized | bool
  - not openshift_use_crio_only | bool

- block:
  - name: Pull CLI Image
    command: >
      atomic pull --storage ostree {{ 'docker:' if system_images_registry == 'docker' else system_images_registry + '/' }}{{ openshift_cli_image }}:{{ openshift_image_tag }}
    register: pull_result
    changed_when: "'Pulling layer' in pull_result.stdout"

  # openshift_container_binary_sync is a custom module in lib_utils
  - name: Copy client binaries/symlinks out of CLI image for use on the host
    openshift_container_binary_sync:
      image: "{{ '' if system_images_registry == 'docker' else system_images_registry + '/' }}{{ openshift_cli_image }}"
      tag: "{{ openshift_image_tag }}"
      backend: "atomic"
  when:
  - openshift_is_containerized | bool
  - openshift_use_crio_only | bool

- name: Reload facts to pick up installed OpenShift version
  openshift_facts:
    system_facts: "{{ vars_openshift_facts_system_facts }}"

- name: Install bash completion for oc tools
  package: name=bash-completion state=present
  when: not openshift_is_containerized | bool
  register: result
  until: result is succeeded
