From fe6c6a3ac6dfb9a2ee0fe5bbf4a7fd46fb9dd894 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Mon, 7 Aug 2017 20:07:50 +0000 Subject: [PATCH] Support docker overlay storage driver This is configured via docker_storage_driver. --- ansible/roles/docker/defaults/main.yml | 4 ++ ansible/roles/docker/tasks/main.yml | 11 +++- ansible/roles/docker/tasks/storage.yml | 60 ++++++++++--------- ansible/roles/docker/templates/daemon.json.j2 | 4 +- etc/kayobe/docker.yml | 4 ++ 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/ansible/roles/docker/defaults/main.yml b/ansible/roles/docker/defaults/main.yml index c43413338..dded0133d 100644 --- a/ansible/roles/docker/defaults/main.yml +++ b/ansible/roles/docker/defaults/main.yml @@ -1,4 +1,8 @@ --- +# Name of the docker storage driver. Supported values include 'devicemapper' +# and 'overlay'. +docker_storage_driver: devicemapper + # Name of the docker storage LVM volume group. docker_storage_volume_group: diff --git a/ansible/roles/docker/tasks/main.yml b/ansible/roles/docker/tasks/main.yml index f9413ad5b..ce611fde9 100644 --- a/ansible/roles/docker/tasks/main.yml +++ b/ansible/roles/docker/tasks/main.yml @@ -1,4 +1,11 @@ --- +- name: Fail when the storage driver is invalid + fail: + msg: > + Storage driver {{ docker_storage_driver }} is invalid. Valid drivers + include 'devicemapper' and 'overlay'. + when: docker_storage_driver not in ['devicemapper', 'overlay'] + - name: Ensure user is in the docker group user: name: "{{ ansible_user_id }}" @@ -40,8 +47,8 @@ - name: Fail when loopback-mode containers or images exist fail: msg: > - Not configuring docker storage in direct-lvm mode as loopback-backed - containers or images exist. + Not configuring docker storage in {{ docker_storage_driver }} mode as + loopback-backed containers or images exist. when: - "{{ 'Data loop file' in docker_info.stdout }}" - "{{ 'Images: 0' not in docker_info.stdout }}" diff --git a/ansible/roles/docker/tasks/storage.yml b/ansible/roles/docker/tasks/storage.yml index 030ac05f5..eed6b6a13 100644 --- a/ansible/roles/docker/tasks/storage.yml +++ b/ansible/roles/docker/tasks/storage.yml @@ -16,35 +16,37 @@ - "/var/lib/docker/containers" become: True -- name: Ensure the docker storage data and metadata volumes exist - lvol: - vg: "{{ docker_storage_volume_group }}" - lv: "{{ item.name }}" - size: "{{ item.size }}" - shrink: no - state: present - with_items: - - name: "{{ docker_storage_volume_thinpool }}" - size: "{{ docker_storage_volume_thinpool_size }}" - - name: "{{ docker_storage_volume_thinpool_meta }}" - size: "{{ docker_storage_volume_thinpool_meta_size }}" - become: True +- block: + - name: Ensure the docker storage data and metadata volumes exist + lvol: + vg: "{{ docker_storage_volume_group }}" + lv: "{{ item.name }}" + size: "{{ item.size }}" + shrink: no + state: present + with_items: + - name: "{{ docker_storage_volume_thinpool }}" + size: "{{ docker_storage_volume_thinpool_size }}" + - name: "{{ docker_storage_volume_thinpool_meta }}" + size: "{{ docker_storage_volume_thinpool_meta_size }}" + become: True -- name: Ensure the docker storage volume is converted to a thinpool - command: > - lvconvert -y --zero n -c 512K - --thinpool {{ docker_storage_volume_group }}/{{ docker_storage_volume_thinpool }} - --poolmetadata {{ docker_storage_volume_group }}/{{ docker_storage_volume_thinpool_meta }} - become: True + - name: Ensure the docker storage volume is converted to a thinpool + command: > + lvconvert -y --zero n -c 512K + --thinpool {{ docker_storage_volume_group }}/{{ docker_storage_volume_thinpool }} + --poolmetadata {{ docker_storage_volume_group }}/{{ docker_storage_volume_thinpool_meta }} + become: True -- name: Ensure the docker storage metadata profile exists - template: - src: docker-thinpool.profile.j2 - dest: /etc/lvm/profile/docker-thinpool.profile - become: True + - name: Ensure the docker storage metadata profile exists + template: + src: docker-thinpool.profile.j2 + dest: /etc/lvm/profile/docker-thinpool.profile + become: True -- name: Ensure the docker storage metadata profile is applied - command: > - lvchange --metadataprofile docker-thinpool - {{ docker_storage_volume_group }}/{{ docker_storage_volume_thinpool }} - become: True + - name: Ensure the docker storage metadata profile is applied + command: > + lvchange --metadataprofile docker-thinpool + {{ docker_storage_volume_group }}/{{ docker_storage_volume_thinpool }} + become: True + when: docker_storage_driver == 'devicemapper' diff --git a/ansible/roles/docker/templates/daemon.json.j2 b/ansible/roles/docker/templates/daemon.json.j2 index e817e5d68..0df640d7c 100644 --- a/ansible/roles/docker/templates/daemon.json.j2 +++ b/ansible/roles/docker/templates/daemon.json.j2 @@ -1,11 +1,13 @@ { - "storage-driver": "devicemapper", + "storage-driver": "{% if docker_storage_driver == 'devicemapper' %}devicemapper{% else %}overlay{% endif %}", {% if docker_daemon_mtu %} "mtu": {{ docker_daemon_mtu }}, {% endif %} "storage-opts": [ +{% if docker_storage_driver == 'devicemapper' %} "dm.thinpooldev=/dev/mapper/{{ docker_storage_volume_group | replace('-', '--') }}-{{ docker_storage_volume_thinpool | replace('-', '--') }}", "dm.use_deferred_removal=true", "dm.use_deferred_deletion=true" +{% endif %} ] } diff --git a/etc/kayobe/docker.yml b/etc/kayobe/docker.yml index 6186b2d7d..abc07a7cc 100644 --- a/etc/kayobe/docker.yml +++ b/etc/kayobe/docker.yml @@ -2,6 +2,10 @@ ############################################################################### # Docker configuration. +# Name of the docker storage driver. Supported values include 'devicemapper' +# and 'overlay'. +#docker_storage_driver: + # Name of the docker storage LVM volume group. #docker_storage_volume_group: