From f8792a73d51bf0d88bb870e994fdc8fa16352b51 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Wed, 15 Jan 2020 21:24:16 +0000 Subject: [PATCH] install-docker: enable setting docker userland proxy This change enables docker user to disable the userland proxy. Do not merge until the default is set to false (used for testing). Change-Id: Ib30e409044ccc48b4c19beae36f1bcd453ebef8e --- roles/install-docker/README.rst | 7 ++++ roles/install-docker/tasks/docker-setup.yaml | 34 +++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/roles/install-docker/README.rst b/roles/install-docker/README.rst index a83e3ad74..3593649bb 100644 --- a/roles/install-docker/README.rst +++ b/roles/install-docker/README.rst @@ -75,3 +75,10 @@ An ansible role to install docker and configure it to use mirrors if available. based on :zuul:rolevar:`install-docker.docker_download_fqdn`. When this option is unset, the role will use distro specific variables which are loaded at the time of execution. + +.. zuul:rolevar:: docker_userland_proxy + :type: bool + + Set to false to disable the docker userland proxy. This variable is useful + when docker is causing routing problem, such as when a kubernetes deployment + is unable to reach its own service. diff --git a/roles/install-docker/tasks/docker-setup.yaml b/roles/install-docker/tasks/docker-setup.yaml index dbc3ecc8d..e398c70ee 100644 --- a/roles/install-docker/tasks/docker-setup.yaml +++ b/roles/install-docker/tasks/docker-setup.yaml @@ -12,5 +12,37 @@ - "{{ docker_group }}" append: yes +- name: Update docker daemon configuration + when: docker_userland_proxy is defined + block: + - name: Check if docker daemon configuration exists + stat: + path: /etc/docker/daemon.json + register: docker_config_stat + - name: Load docker daemon configuration + when: docker_config_stat.stat.exists + slurp: + path: /etc/docker/daemon.json + register: docker_config + - name: Parse docker daemon configuration + when: docker_config_stat.stat.exists + set_fact: + docker_config: "{{ docker_config.content | b64decode | from_json }}" + - name: Set default docker daemon configuration + when: not docker_config_stat.stat.exists + set_fact: + docker_config: {} + - name: Add registry to docker daemon configuration + vars: + new_config: + userland-proxy: "{{ docker_userland_proxy }}" + set_fact: + docker_config: "{{ docker_config | combine(new_config) }}" + - name: Save docker daemon configuration + copy: + content: "{{ docker_config | to_nice_json }}" + dest: /etc/docker/daemon.json + become: true + - name: Reset ssh connection to pick up docker group - meta: reset_connection \ No newline at end of file + meta: reset_connection