From 94c177755c23f95efff07c5ec9683b784adfeda6 Mon Sep 17 00:00:00 2001 From: iMSCORPiAN Date: Thu, 29 Sep 2022 13:30:05 +0200 Subject: [PATCH] Add docker service configuration options --- README.md | 7 +++++++ defaults/main.yml | 3 +++ tasks/main.yml | 8 ++++++++ templates/http-proxy.conf.j2 | 4 ++++ 4 files changed, 22 insertions(+) create mode 100644 templates/http-proxy.conf.j2 diff --git a/README.md b/README.md index 2f23291..ff9413d 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,13 @@ A list of system users to be added to the `docker` group (so they can use Docker Custom `dockerd` options can be configured through this dictionary representing the json file `/etc/docker/daemon.json`. + docker_service_settings: + - HTTP_PROXY=http://proxy.example.com:80 + - HTTPS_PROXY=https://proxy.example.com:443 + - NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp + +Custom docker service configuration. Should only be used for `HTTP/HTTPS proxy` settings. + ## Use with Ansible (and `docker` Python library) Many users of this role wish to also use Ansible to then _build_ Docker images and manage Docker containers on the server where Docker is installed. In this case, you can easily add in the `docker` Python library using the `geerlingguy.pip` role: diff --git a/defaults/main.yml b/defaults/main.yml index 685b8de..070e6fa 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -47,3 +47,6 @@ docker_users: [] # Docker daemon options as a dict docker_daemon_options: {} + +# Docker HTTP/HTTPS proxy settings as list of environment configurations +docker_service_settings: [] diff --git a/tasks/main.yml b/tasks/main.yml index dcd47de..075d093 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -65,6 +65,14 @@ when: docker_daemon_options.keys() | length > 0 notify: restart docker +- name: Configure docker service environment. + template: + src: http-proxy.conf.j2 + dest: /etc/systemd/system/docker.service.d/http-proxy.conf + mode: 0644 + when: docker_service_settings | length > 0 + notify: restart docker + - name: Ensure Docker is started and enabled at boot. service: name: docker diff --git a/templates/http-proxy.conf.j2 b/templates/http-proxy.conf.j2 new file mode 100644 index 0000000..7a059db --- /dev/null +++ b/templates/http-proxy.conf.j2 @@ -0,0 +1,4 @@ +[Service] +{% for docker_service_setting in docker_service_settings %} +Environment="{{ docker_service_setting }}" +{% endfor %}