From adceaf60e18c71269dde939f4e43aed6c8ba91fa Mon Sep 17 00:00:00 2001
From: Spencer Smith <robertspencersmith@gmail.com>
Date: Tue, 10 May 2016 15:49:27 -0700
Subject: [PATCH] support proxies with docker on rhel

---
 inventory/group_vars/all.yml              |  5 +++++
 roles/docker/tasks/main.yml               |  5 +++++
 roles/docker/tasks/rhel-proxies.yml       | 21 +++++++++++++++++++++
 roles/docker/templates/http-proxy.conf.j2 |  3 +++
 4 files changed, 34 insertions(+)
 create mode 100644 roles/docker/tasks/rhel-proxies.yml
 create mode 100644 roles/docker/templates/http-proxy.conf.j2

diff --git a/inventory/group_vars/all.yml b/inventory/group_vars/all.yml
index 836e40107..aa6ac5426 100644
--- a/inventory/group_vars/all.yml
+++ b/inventory/group_vars/all.yml
@@ -123,3 +123,8 @@ dns_server: "{{ kube_service_addresses|ipaddr('net')|ipaddr(2)|ipaddr('address')
 #    server master2 10.99.0.27:443
 #    balance roundrobin
 # apiserver_loadbalancer_domain_name: "lb-apiserver.kubernetes.local"
+
+##Set these proxy values in order to update docker daemon to use proxies
+#http_proxy: ""
+#https_proxy: ""
+#no_proxy: ""
diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml
index 47e5d24a1..116f2f9f6 100644
--- a/roles/docker/tasks/main.yml
+++ b/roles/docker/tasks/main.yml
@@ -53,6 +53,11 @@
   with_items: "{{ docker_package_info.pkgs }}"
   when: docker_package_info.pkgs|length > 0
 
+- name: allow for proxies on RHEL systems
+  include: rhel-proxies.yml
+  when: ansible_distribution in ["CentOS","RedHat"] and
+        ansible_distribution_major_version >= 7
+
 - meta: flush_handlers
 
 - name: ensure docker service is started and enabled
diff --git a/roles/docker/tasks/rhel-proxies.yml b/roles/docker/tasks/rhel-proxies.yml
new file mode 100644
index 000000000..10fafb618
--- /dev/null
+++ b/roles/docker/tasks/rhel-proxies.yml
@@ -0,0 +1,21 @@
+---
+- name: create docker service directory for RHEL family
+  file: path=/etc/systemd/system/docker.service.d state=directory
+  when: ansible_distribution in ["CentOS","RedHat"] and
+        ansible_distribution_major_version >= 7
+
+- name: drop docker environment for RHEL family
+  template:
+    src: http-proxy.conf.j2
+    dest: /etc/systemd/system/docker.service.d/http-proxy.conf
+  when: ansible_distribution in ["CentOS","RedHat"] and
+        ansible_distribution_major_version >= 7
+  register: rheldockerproxy
+
+- name: reload systemctl daemons for RHEL family
+  shell: systemctl daemon-reload
+  when: rheldockerproxy.changed
+
+- name: restart docker for RHEL family
+  service: name=docker state=restarted
+  when: rheldockerproxy.changed
diff --git a/roles/docker/templates/http-proxy.conf.j2 b/roles/docker/templates/http-proxy.conf.j2
new file mode 100644
index 000000000..7e558837c
--- /dev/null
+++ b/roles/docker/templates/http-proxy.conf.j2
@@ -0,0 +1,3 @@
+[Service]
+
+Environment={% if http_proxy %}"HTTP_PROXY={{ http_proxy }}"{% endif %} {% if https_proxy %}"HTTPS_PROXY={{ https_proxy }}"{% endif %} {% if no_proxy %}"NO_PROXY={{ no_proxy }}"{% endif %}
-- 
GitLab