---
  # main tasks to install docker

- name: install packages
  apt:
    state: installed
    package: "{{ item }}"
    update_cache: yes
    cache_valid_time: 3600
  with_items:
    - "htop"
    - "wget"
    - "apt-transport-https"
    - "ca-certificates"
    - "glusterfs-client"
    - xfsprogs
    - attr
    - virtualbox-guest-additions-iso

#- name: install repo keys
#  apt_key:
#    keyserver: hkp://ha.pool.sks-keyservers.net:80
#    id: 58118E89F3A912897C070ADBF76221572C52609D

- name: install apt repo
  apt_repository:
    repo: deb https://apt.dockerproject.org/repo ubuntu-xenial main
    state: present

- name: import repo key
  apt_key:
    id: 58118E89F3A912897C070ADBF76221572C52609D
    keyserver: "hkp://ha.pool.sks-keyservers.net:80"
    state: present

- name: install prerequisits
  shell: apt-get -y install linux-image-extra-$(uname -r) linux-image-extra-virtual


- name: create docker group
  group: state=present name=docker gid=999 system=yes

- name: add users to docker group
  user: name={{ item }} groups=docker append=yes
  with_items: "{{ dockerhost.users }}"


- name: install via apt
  apt:
    state: latest
    update_cache: true
    package: "{{ item }}"
  with_items:
    - docker-engine
#    - virtualbox-guest-dkms

- name: copy docker config file
  copy:
    src: daemon.json
    dest: /etc/docker/daemon.json
  notify:
    - restart docker

#- name: create mount points for shares
#  file:
#    state: absent
#    mode: 0774
#    group: docker
#    dest: /opt/shared
#
#- name: create mount points for shares
#  file:
#    state: link
#    mode: 0774
#    group: docker
#    src: /media/sf_dkhost
#    dest: /opt/shared



## install docker-compose
- name: install docker-compose from git repo
  shell: |
          curl -L https://github.com/docker/compose/releases/download/1.13.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
          chmod +x /usr/local/bin/docker-compose

## expose the docker daemon on tcp
- name: expose docker daemon
  file:
    state: directory
    path: /etc/systemd/system/docker.service.d

- name: expose docker daemon
  copy:
    src: docker.service.host.conf
    dest: /etc/systemd/system/docker.service.d/host.conf
  notify:
    - restart docker

