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
This commit is contained in:
Tristan Cacqueray
2020-01-15 21:24:16 +00:00
parent 211e92ec40
commit f8792a73d5
2 changed files with 40 additions and 1 deletions

View File

@@ -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 based on :zuul:rolevar:`install-docker.docker_download_fqdn`. When this
option is unset, the role will use distro specific variables which are option is unset, the role will use distro specific variables which are
loaded at the time of execution. 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.

View File

@@ -12,5 +12,37 @@
- "{{ docker_group }}" - "{{ docker_group }}"
append: yes 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 - name: Reset ssh connection to pick up docker group
meta: reset_connection meta: reset_connection