---
# 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: 58118E89F3A912897C070ADBF76221572C52609D
    state: present
  register: apt_key_docker_repo

- name: add docker's apt repository ({{ ansible_distribution | lower }}-{{ ansible_distribution_release }})
  apt_repository:
    repo: deb https://apt.dockerproject.org/repo {{ ansible_distribution | lower }}-{{ ansible_distribution_release }} main
    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-engine={{ docker_version }}*
