---
- set_fact:
    l_use_crio: "{{ openshift_docker_use_crio | default(false) }}"

- name: Install clients
  package: name={{ openshift.common.service_type }}-clients state=present
  when: not openshift.common.is_containerized | bool

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

  - name: Copy client binaries/symlinks out of CLI image for use on the host
    openshift_container_binary_sync:
      image: "{{ openshift.common.cli_image }}"
      tag: "{{ openshift_image_tag }}"
      backend: "docker"
  when:
  - openshift.common.is_containerized | bool
  - not l_use_crio

- block:
  - name: Pull CLI Image
    command: >
      atomic pull --storage ostree {{ openshift.common.system_images_registry }}/{{ openshift.common.cli_image }}:{{ openshift_image_tag }}
    register: pull_result
    changed_when: "'Pulling layer' in pull_result.stdout"

  - name: Copy client binaries/symlinks out of CLI image for use on the host
    openshift_container_binary_sync:
      image: "{{ openshift.common.system_images_registry }}/{{ openshift.common.cli_image }}"
      tag: "{{ openshift_image_tag }}"
      backend: "atomic"
  when:
  - openshift.common.is_containerized | bool
  - l_use_crio

- name: Reload facts to pick up installed OpenShift version
  openshift_facts:

- name: Install bash completion for oc tools
  package: name=bash-completion state=present
  when: not openshift.common.is_containerized | bool
