diff --git a/defaults/main.yml b/defaults/main.yml index 3a9cc47..dfa5eda 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -27,3 +27,8 @@ docker_yum_repo_enable_test: 0 # A list of users who will be added to the docker group. docker_users: [] + +# proxy settings +http_proxy: "" +https_proxy: "" +no_proxy: "" diff --git a/tasks/docker-service.yml b/tasks/docker-service.yml new file mode 100644 index 0000000..f455ae0 --- /dev/null +++ b/tasks/docker-service.yml @@ -0,0 +1,16 @@ +--- +- name: Ensure docker service dir exists. + file: + path: /etc/systemd/system/docker.service.d + state: directory + +- name: Add Docker configuration with proxy set. + template: + src: proxy.conf.j2 + dest: /etc/systemd/system/docker.service.d/proxy.conf + register: proxy_template + +- name: Reload systemd daemon if template is changed. + systemd: + daemon_reload: true + when: proxy_template is changed diff --git a/tasks/main.yml b/tasks/main.yml index 8968c77..9e1de7e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,6 +15,9 @@ - import_tasks: docker-1809-shim.yml when: ansible_service_mgr == 'systemd' +- import_tasks: docker-service.yml + when: ansible_service_mgr == 'systemd' + - name: Ensure Docker is started and enabled at boot. service: name: docker diff --git a/templates/proxy.conf.j2 b/templates/proxy.conf.j2 new file mode 100644 index 0000000..2e3ad55 --- /dev/null +++ b/templates/proxy.conf.j2 @@ -0,0 +1,5 @@ +# {{ ansible_managed }} +[Service] +Environment='HTTP_PROXY={{ http_proxy }}' +Environment='HTTPS_PROXY={{ https_proxy }}' +Environment='NO_PROXY={{ no_proxy }}' \ No newline at end of file