---
- name: stop docker
  service: name=docker state=stopped
  ignore_errors: yes

- name: remove any existing docker-storage config file
  file:
    path: /etc/sysconfig/docker-storage
    state: absent

- block:
    - name: create the docker-storage-setup overlayfs config file
      template:
        src: "{{ role_path }}/templates/docker-storage-setup-overlayfs.j2"
        dest: /etc/sysconfig/docker-storage-setup
        owner: root
        group: root
        mode: 0644
  when:
    - ansible_distribution_version | version_compare('7.4', '>=')
    - ansible_distribution == "RedHat"

- block:
    - name: create the docker-storage-setup devicemapper config file
      template:
        src: "{{ role_path }}/templates/docker-storage-setup-dm.j2"
        dest: /etc/sysconfig/docker-storage-setup
        owner: root
        group: root
        mode: 0644
  when:
    - ansible_distribution_version | version_compare('7.4', '<')
    - ansible_distribution == "RedHat"

- block:
    - name: create the docker-storage-setup devicemapper config file for CentOS
      template:
        src: "{{ role_path }}/templates/docker-storage-setup-dm.j2"
        dest: /etc/sysconfig/docker-storage-setup
        owner: root
        group: root
        mode: 0644

  # TODO(shadower): Find out which CentOS version supports overlayfs2
  when:
    - ansible_distribution == "CentOS"

- name: Install Docker
  package: name=docker state=present
  when: not openshift.common.is_atomic | bool

- name: start docker
  service: name=docker state=restarted enabled=true

- block:
    - name: (Atomic) Remove extra docker lv from root vg
      lvol:
        lv: docker-pool
        vg: atomicos
        state: absent
        force: yes
    - name: (Atomic) Grow root lv to fill vg
      lvol:
        lv: root
        vg: atomicos
        size: +100%FREE
    - name: (Atomic) Grow root fs to match lv
      filesystem:
        dev: /dev/mapper/atomicos-root
        fstype: xfs
        resizefs: yes
    - name: (Atomic) Force Ansible to re-gather disk facts
      setup:
        filter: 'ansible_mounts'
  when: openshift.common.is_atomic | bool
...
