---
- include_tasks: setup-ubuntu.yml
  when: ansible_os_family == 'Debian'

- name: Install Docker.
  package:
    name: "{{ docker_package }}"
    state: "{{ docker_package_state }}"
  become: yes

- name: Ensure Docker is started and enabled at boot.
  service:
    name: docker
    state: "{{ docker_service_state }}"
    enabled: "{{ docker_service_enabled }}"

- name: Ensure handlers are notified now to avoid firewall conflicts.
  meta: flush_handlers

- name: Ensure docker users are added to the docker group.
  user:
    name: "{{ ansible_user }}"
    groups: docker
    append: true
  become: yes

- name: reset ssh connection to allow user changes to affect 'current login user'
  meta: reset_connection

- name: Check current docker-compose version.
  command: docker-compose --version
  register: docker_compose_current_version
  changed_when: false
  failed_when: false

- name: Delete existing docker-compose version if it's different.
  file:
    path: "{{ docker_compose_path }}"
    state: absent
  when: >
    docker_compose_current_version.stdout is defined
    and docker_compose_version not in docker_compose_current_version.stdout
  become: yes

- name: Install Docker-compose
  get_url:
    url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64
    dest: "{{ docker_compose_path }}"
    mode: 0755
  become: yes
