Support docker overlay storage driver

This is configured via docker_storage_driver.
This commit is contained in:
Mark Goddard 2017-08-07 20:07:50 +00:00
parent d20118a9c5
commit fe6c6a3ac6
5 changed files with 51 additions and 32 deletions

View File

@ -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:

View File

@ -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 }}"

View File

@ -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'

View File

@ -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 %}
]
}

View File

@ -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: