# Copyright 2020 The Kubernetes Authors.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---

# Requires license. If you running on Azure License is currently provided with Windows Server images.
- name: Install docker via OneGet
  win_shell: |
    Install-PackageProvider -Name DockerMsftProvider -Force -ForceBootstrap | Out-Null
    $package = Find-Package -Name Docker -ProviderName DockerMsftProvider -RequiredVersion {{ docker_ee_version }}
    $package | Install-Package -Force | Out-Null

- name: Start Docker Service 
  win_service:
    name: docker
    start_mode: auto
    state: started

- name: Set up Docker Network
  win_shell: |
    $exists=docker network ls -f name=host -q
    if (-not $exists) { docker network create -d nat host }

- name: Pre-pull docker images
  win_command: docker pull {{ item }}
  loop: "{{ images }}"
  async: 1800
  poll: 60
  retries: 5
  register: pull
  until: pull is not failed
  when: (prepull | bool)
  vars:
    images: "{{ prepull_images[distribution_version] | default([]) }}"