---
# Debian / Ubuntu specific:

- name: install dependencies for docker repository
  package:
    name: "{{ item }}"
    state: present
  with_items:
    - apt-transport-https
    - ca-certificates

- name: add apt key for the docker repository
  apt_key:
    keyserver: hkp://ha.pool.sks-keyservers.net:80
    id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
    state: present
  register: apt_key_docker_repo

- name: add docker's apt repository ({{ ansible_distribution | lower }}-{{ ansible_distribution_release }})
  apt_repository:
    repo: deb https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename|lower }} stable
    state: present
  register: apt_docker_repo

- name: update apt's cache
  apt:
    update_cache: yes
  when: apt_key_docker_repo.changed or apt_docker_repo.changed

- name: install docker-engine
  package:
    name: "{{ item }}"
    state: present
  with_items:
    - docker-ce={{ docker_version }}*
