From ffb63b65e3ab3bf5fcd69b35d735c0a3ea7f218b Mon Sep 17 00:00:00 2001 From: Mihai Vultur Date: Wed, 18 Mar 2020 18:16:29 +0000 Subject: [PATCH] Add the possibility to customize the options in '/etc/docker/daemon.json'. --- README.md | 10 ++++++++++ defaults/main.yml | 5 +++++ tasks/main.yml | 11 +++++++++++ templates/docker-daemon.json.j2 | 1 + 4 files changed, 27 insertions(+) create mode 100644 templates/docker-daemon.json.j2 diff --git a/README.md b/README.md index 036b560..c9ac194 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,16 @@ Available variables are listed below, along with default values (see `defaults/m The `docker_edition` should be either `ce` (Community Edition) or `ee` (Enterprise Edition). You can also specify a specific version of Docker to install using the distribution-specific format: Red Hat/CentOS: `docker-{{ docker_edition }}-`; Debian/Ubuntu: `docker-{{ docker_edition }}=`. +You can customize `daemon configuration` by providing `daemon.json` values in yaml format. Example: + + docker_config_options: + exec-opts: + - native.cgroupdriver=systemd + log-driver: journald + max-concurrent-downloads: 7 + max-concurrent-uploads: 5 + storage-driver: overlay2 + You can control whether the package is installed, uninstalled, or at the latest version by setting `docker_package_state` to `present`, `absent`, or `latest`, respectively. Note that the Docker daemon will be automatically restarted if the Docker package is updated. This is a side effect of flushing all handlers (running any of the handlers that have been notified by this and any other role up to this point in the play). docker_service_state: started diff --git a/defaults/main.yml b/defaults/main.yml index ba5ba8a..6fa3dda 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,6 +9,11 @@ docker_service_state: started docker_service_enabled: true docker_restart_handler_state: restarted +# Docker config options. +docker_config_options: + max-concurrent-downloads: 5 + max-concurrent-uploads: 5 + # Docker Compose options. docker_install_compose: true docker_compose_version: "1.25.4" diff --git a/tasks/main.yml b/tasks/main.yml index 56449ef..a680bea 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,6 +11,17 @@ state: "{{ docker_package_state }}" notify: restart docker +- name: Ensure /etc/docker exists + file: + path: /etc/docker + state: directory + +- name: Install daemon.json + template: + src: docker-daemon.json.j2 + dest: /etc/docker/daemon.json + notify: restart docker + - name: Ensure Docker is started and enabled at boot. service: name: docker diff --git a/templates/docker-daemon.json.j2 b/templates/docker-daemon.json.j2 new file mode 100644 index 0000000..34826d7 --- /dev/null +++ b/templates/docker-daemon.json.j2 @@ -0,0 +1 @@ +{{ docker_config_options | default([])| to_nice_json }}