Add proxies to docker role

This commit is contained in:
Tibor Csóka 2019-04-25 15:42:19 +02:00
parent 86c5b3f887
commit c06a13c5a4
No known key found for this signature in database
GPG Key ID: 3BDA28CC47DCD2F1
5 changed files with 46 additions and 2 deletions

View File

@ -1,3 +1,9 @@
---
- name: restart docker
service: "name=docker state={{ docker_restart_handler_state }}"
service:
name: docker
state: "{{ docker_restart_handler_state }}"
- name: reload systemd daemon
systemd:
daemon_reload: true

View File

@ -1,4 +1,5 @@
---
- include_tasks: setup-RedHat.yml
when: ansible_os_family == 'RedHat'
@ -15,6 +16,8 @@
- import_tasks: docker-1809-shim.yml
when: ansible_service_mgr == 'systemd'
- import_tasks: proxies.yml
- name: Ensure Docker is started and enabled at boot.
service:
name: docker

24
tasks/proxies.yml Normal file
View File

@ -0,0 +1,24 @@
---
- name: Add proxies into systemd environment
when:
- ansible_service_mgr == 'systemd'
- >-
ansible_env['http_proxy'] is defined or
ansible_env['HTTP_PROXY'] is defined or
ansible_env['https_proxy'] is defined or
ansible_env['HTTPS_PROXY'] is defined
block:
- name: Establish docker service config dir
file:
dest: /etc/systemd/system/docker.service.d/
state: directory
recurse: true
- name: Establish docker proxy config
template:
src: proxies.conf.j2
dest: /etc/systemd/system/docker.service.d/proxies.conf
notify:
- reload systemd daemon
- restart docker

View File

@ -28,7 +28,8 @@
when: add_repository_key is failed
- name: Add Docker apt key (alternative for older systems without SNI).
shell: sudo apt-key add /tmp/docker-repo-key
become: true
command: apt-key add /tmp/docker-repo-key
args:
warn: false
when: add_repository_key is failed

10
templates/proxies.conf.j2 Normal file
View File

@ -0,0 +1,10 @@
# {{ ansible_managed }}
[Service]
{% for proxy in ['http_proxy', 'https_proxy'] -%}
{% if proxy in ansible_env %}
{{- 'Environment= "%s=%s"\n' | format(proxy | upper, ansible_env[proxy]) -}}
{% elif proxy | upper in ansible_env %}
{{- 'Environment= "%s=%s"\n' | format(proxy | upper, ansible_env[proxy | upper]) -}}
{%- endif -%}
{%- endfor -%}