---
# tasks file for docker
- name: Ensure old versions of Docker are not installed.
  package:
    name:
      - docker
      - docker-common
      - docker-engine
    state: absent

- name: setup Debian system
  include_tasks: Debian.yml
  when: ansible_distribution == "Debian"

- name: setup RedHat system
  include_tasks: CentOS.yml
  when: ansible_distribution == "CentOS"

- name: setup Ubuntu system
  include_tasks: Ubuntu.yml
  when: ansible_distribution == 'Ubuntu'

- name: setup RedHat system
  include_tasks: RedHat.yml
  when: ansible_distribution == 'RedHat'

- name: Install Docker and containerd.
  package:
    name: "{{ item }}"
    state: present
  with_items:
    - docker-ce
    - docker-ce-cli
    - containerd.io
    - python3-pip

- name: Create systemd docker.service.d.
  file:
    path: '/etc/systemd/system/docker.service.d'
    state: directory
    owner: root
    group: root
    mode: '0644'
  notify: restart docker

- name: Template Proxy Settings for Docker Daemon.
  template:
    src: 'docker-proxy.conf'
    dest: '/etc/systemd/system/docker.service.d/docker-proxy.conf'
    owner: root
    group: root
    mode: '0644'

- name: Ensure Docker is started and enabled at boot.
  service:
    name: docker
    state: started
    enabled: true

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

- name: install docker / docker-compose sdk
  pip:
    name:
      - docker
      - docker-compose
  vars:
    ansible_python_interpreter: /usr/bin/python3
  environment:
    http_proxy: "{{ mmw_proxy|default('') }}"
    https_proxy: "{{ mmw_proxy|default('') }}"


- name: install docker-compose
  get_url:
    dest: /usr/local/bin/docker-compose
    url: "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64"
    mode: '0755'
  environment:
    https_proxy: "{{ mmw_proxy|default('') }}"
...
