---
- block:
  - name: sync_container | Gather information about the current image (how to download, is it cached etc.)
    import_tasks: set_container_facts.yml
    tags:
    - facts

  - name: sync_container | Upload container image to node
    synchronize:
      src: "{{ image_path_cached }}"
      dest: "{{ image_path_final }}"
      use_ssh_args: "{{ has_bastion | default(false) }}"
      mode: push
    delegate_facts: no
    register: get_task
    become: true
    until: get_task is succeeded
    retries: 4
    delay: "{{ retry_stagger | random + 3 }}"
    when:
    - ansible_os_family not in ["CoreOS", "Coreos", "Container Linux by CoreOS"]

  - name: sync_container | Load container image into docker
    shell: "{{ docker_bin_dir }}/docker load < {{ image_path_final }}"
    when:
    - ansible_os_family not in ["CoreOS", "Coreos", "Container Linux by CoreOS"]

  - name: sync_container | Remove container image from cache
    file:
      state: absent
      path: "{{ image_path_final }}"
    when:
    - not download_keep_remote_cache
    - ansible_os_family not in ["CoreOS", "Coreos", "Container Linux by CoreOS"]

  tags:
  - upload
