Skip to content

Commit

Permalink
set http(s)_proxy for docker daemon in systemd environment (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
menghan authored and angstwad committed Oct 12, 2017
1 parent fb4905d commit de8e8c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ docker_group_members: []
# if docker_http_proxy is undefined the role will not set/modify any ENV vars
docker_http_proxy:
docker_https_proxy:
docker_no_proxy:

# Flags for whether to install pip packages
pip_install_pip: true
Expand Down
31 changes: 28 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@
set_fact:
is_systemd: false
changed_when: false
tags: always

- name: Set systemd playbook var
set_fact:
is_systemd: true
when: ( ansible_lsb.id|lower == "ubuntu" and ansible_distribution_version|version_compare('15.04', '>=') or ansible_lsb.id|lower == "debian" )
tags: always

# https://github.com/moby/moby/issues/25471#issuecomment-263101090
- name: Creates override directory (systemd)
Expand All @@ -132,7 +134,9 @@
owner: root
group: root
mode: 0755
when: daemon_json != "" and is_systemd
when:
- is_systemd
- daemon_json != '' or (docker_http_proxy|default('')) != '' or (docker_https_proxy|default('')) != ''

- name: Set docker daemon override (systemd)
copy:
Expand Down Expand Up @@ -264,7 +268,9 @@
regexp: "^export HTTP_PROXY="
line: "export HTTP_PROXY=\"{{docker_http_proxy}}\""
state: present
when: docker_http_proxy is defined and (docker_http_proxy != None)
when:
- not is_systemd
- (docker_http_proxy|default('')) != ''
notify:
- Restart docker
tags: proxy
Expand All @@ -275,9 +281,28 @@
regexp: "^export HTTPS_PROXY="
line: "export HTTPS_PROXY=\"{{docker_https_proxy}}\""
state: present
when: docker_https_proxy is defined and (docker_https_proxy != None)
when:
- not is_systemd
- (docker_https_proxy|default('')) != ''
notify:
- Restart docker
tags: proxy

- name: Set docker HTTP(S)_PROXY if docker_http(s)_proxy defined (systemd)
copy:
content: |
[Service]
Environment="HTTP_PROXY={{ docker_http_proxy }} HTTPS_PROXY={{ docker_https_proxy | default('') }} NO_PROXY={{ docker_no_proxy | default('') }}"
dest: /etc/systemd/system/docker.service.d/proxy.conf
owner: root
group: root
mode: 0644
notify:
- Reload systemd
- Restart docker
when:
- is_systemd
- (docker_http_proxy|default('')) != '' or (docker_https_proxy|default('')) != ''
tags: proxy

- name: Start docker
Expand Down

0 comments on commit de8e8c8

Please sign in to comment.