---
- name: Docker | include global vars for minions
  include_vars: "{{ansible_tmp_dir}}/generated_global_vars.yml"
  when: not master

- name: Docker | include vars
  include_vars: "{{ ansible_distribution|lower }}.yml"

- name: Docker | ensure docker repository public key is installed
  action: "{{ docker_repo_key_info.pkg_key }}"
  args:
    id: "{{item}}"
    url: "{{docker_repo_key_info.url}}"
    state: present
  register: keyserver_task_result
  until: keyserver_task_result|succeeded
  retries: 3
  with_items: "{{ docker_repo_key_info.repo_keys }}"

- name: Docker | ensure docker repository is enabled
  action: "{{ docker_repo_info.pkg_repo }}"
  args:
    repo: "{{item}}"
    state: present
  with_items: "{{ docker_repo_info.repos }}"

- name: Docker | ensure docker packages are installed
  action: "{{ docker_package_info.pkg_mgr }}"
  args:
    pkg: "{{item.name}}"
    force: "{{item.force|default(omit)}}"
    state: present
  register: docker_task_result
  until: docker_task_result|succeeded
  retries: 3
  with_items: "{{ docker_package_info.pkgs }}"

- name: Docker | restart docker
  include_tasks: ./restart_docker.yml
  when: docker_task_result.changed
