
- name: Check for appropriate Docker versions
  hosts: oo_masters_to_config:oo_nodes_to_upgrade:oo_etcd_to_config
  roles:
  - openshift_facts
  tasks:
  - set_fact:
      repoquery_cmd: "{{ 'dnf repoquery --latest-limit 1 -d 0' if ansible_pkg_mgr == 'dnf' else 'repoquery --plugins' }}"

  - fail:
      msg: Cannot upgrade Docker on Atomic operating systems.
    when: openshift.common.is_atomic | bool

  - include: ../../../../common/openshift-cluster/upgrades/docker/upgrade_check.yml
    when: docker_upgrade is not defined or docker_upgrade | bool


# If a node fails, halt everything, the admin will need to clean up and we
# don't want to carry on, potentially taking out every node. The playbook can safely be re-run
# and will not take any action on a node already running the requested docker version.
- name: Evacuate and upgrade nodes
  hosts: oo_masters_to_config:oo_nodes_to_upgrade:oo_etcd_to_config
  serial: 1
  any_errors_fatal: true
  tasks:
  - name: Prepare for Node evacuation
    command: >
      {{ openshift.common.client_binary }} adm manage-node {{ openshift.common.hostname | lower }} --schedulable=false
    delegate_to: "{{ groups.oo_first_master.0 }}"
    when: l_docker_upgrade is defined and l_docker_upgrade | bool and inventory_hostname in groups.oo_nodes_to_upgrade

  - name: Evacuate Node for Kubelet upgrade
    command: >
      {{ openshift.common.client_binary }} adm manage-node {{ openshift.common.hostname | lower }} --evacuate --force
    delegate_to: "{{ groups.oo_first_master.0 }}"
    when: l_docker_upgrade is defined and l_docker_upgrade | bool and inventory_hostname in groups.oo_nodes_to_upgrade

  - include: ../../../../common/openshift-cluster/upgrades/docker/upgrade.yml
    when: l_docker_upgrade is defined and l_docker_upgrade | bool

  - name: Set node schedulability
    command: >
      {{ openshift.common.client_binary }} adm manage-node {{ openshift.common.hostname | lower }} --schedulable=true
    delegate_to: "{{ groups.oo_first_master.0 }}"
    when:
    - l_docker_upgrade is defined
    - l_docker_upgrade | bool
    - inventory_hostname in groups.oo_nodes_to_upgrade
    - openshift.node.schedulable | bool

