From 17c9f9a080227f32db2d7a5647d9b4859fec745a Mon Sep 17 00:00:00 2001 From: Adrian Bienkowski Date: Mon, 15 Jun 2020 06:07:28 -0400 Subject: [PATCH] add support for proxy inside containers --- handlers/main.yml | 10 +++++++++- tasks/docker-service-proxy.yml | 17 +++++++++++++++++ tasks/main.yml | 8 ++++++++ templates/http_proxy.conf.j2 | 2 ++ templates/https_proxy.conf.j2 | 2 ++ templates/no_proxy.conf.j2 | 2 ++ 6 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tasks/docker-service-proxy.yml create mode 100644 templates/http_proxy.conf.j2 create mode 100644 templates/https_proxy.conf.j2 create mode 100644 templates/no_proxy.conf.j2 diff --git a/handlers/main.yml b/handlers/main.yml index 7847bc1..b03ad69 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,3 +1,11 @@ --- +- name: reload systemd + systemd: + daemon_reload: yes + become: yes + - name: restart docker - service: "name=docker state={{ docker_restart_handler_state }}" + service: + name: docker + state: "{{ docker_restart_handler_state }}" + become: yes diff --git a/tasks/docker-service-proxy.yml b/tasks/docker-service-proxy.yml new file mode 100644 index 0000000..15a9532 --- /dev/null +++ b/tasks/docker-service-proxy.yml @@ -0,0 +1,17 @@ +--- +- name: create a service directory + file: + path: /etc/systemd/system/docker.service.d + state: directory + +- name: add proxy configuration for docker service + template: + dest: "/etc/systemd/system/docker.service.d/{{ item }}.conf" + src: "{{ item }}.conf.j2" + with_items: + - http_proxy + - https_proxy + - no_proxy + notify: + - reload systemd + - restart docker diff --git a/tasks/main.yml b/tasks/main.yml index 56449ef..94f2617 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,6 +11,13 @@ state: "{{ docker_package_state }}" notify: restart docker +- include_tasks: docker-service-proxy.yml + when: + - http_proxy is defined + - https_proxy is defined + - no_proxy is defined + - enable_proxy is defined and enable_proxy|bool + - name: Ensure Docker is started and enabled at boot. service: name: docker @@ -25,3 +32,4 @@ - include_tasks: docker-users.yml when: docker_users | length > 0 + diff --git a/templates/http_proxy.conf.j2 b/templates/http_proxy.conf.j2 new file mode 100644 index 0000000..2f07b2d --- /dev/null +++ b/templates/http_proxy.conf.j2 @@ -0,0 +1,2 @@ +[Service] +Environment="HTTP_PROXY={{ http_proxy }}" diff --git a/templates/https_proxy.conf.j2 b/templates/https_proxy.conf.j2 new file mode 100644 index 0000000..23e2422 --- /dev/null +++ b/templates/https_proxy.conf.j2 @@ -0,0 +1,2 @@ +[Service] +Environment="HTTPS_PROXY={{ https_proxy }}" diff --git a/templates/no_proxy.conf.j2 b/templates/no_proxy.conf.j2 new file mode 100644 index 0000000..334e98d --- /dev/null +++ b/templates/no_proxy.conf.j2 @@ -0,0 +1,2 @@ +[Service] +Environment="NO_PROXY={{ no_proxy }}"