Enable http proxy and no proxy configuration in engine

The proxy information will be achieved from idf with the following
format:
proxy_settings:
  http_proxy: <http_proxy>
  https_proxy: <https_proxy>
  no_proxy: <localhost and all the ports in k8s inventory file>

This change supposes that jumphost(localhost) and target hosts have
same proxy configuration. After post-deployment, re-login to the
jumphost is needed to let 'no_proxy' configuration on jumphost take effect
Otherwise, kubectl will get 'Unable to connect to the server: EOF' error.

Change-Id: I50f74d630dfd5d3bdf14f1e22824961cf99427ba
diff --git a/playbooks/roles/configure-targethosts/tasks/configure-network-Debian.yml b/playbooks/roles/configure-targethosts/tasks/configure-network-Debian.yml
index ac9a9ff..aac29aa 100644
--- a/playbooks/roles/configure-targethosts/tasks/configure-network-Debian.yml
+++ b/playbooks/roles/configure-targethosts/tasks/configure-network-Debian.yml
@@ -72,6 +72,31 @@
     line: "DNS={{ idf.net_config[engine.public_network | default('public')].dns | join(' ')}}"
   when: idf.net_config[engine.public_network | default('public')].dns is defined
 
+- name: Proxy configuration for apt
+  block:
+  - name: Check that the /etc/apt/apt.conf exists
+    stat:
+      path: /etc/apt/apt.conf
+    register: stat_result
+
+  - name: Create /etc/apt/apt.conf, if it doesn't exist
+    file:
+      path: /etc/apt/apt.conf
+      state: touch
+    when: stat_result.stat.exists == False
+
+  - name: Add proxy setting to /etc/apt/apt.conf
+    lineinfile:
+      dest: /etc/apt/apt.conf
+      state: present
+      regexp: "^{{ item.name }}"
+      line: "{{ item.name }} {{ item.value }} "
+    with_items:
+      - {name: 'Acquire::http::Proxy', value: '"{{ idf.proxy_settings.http_proxy }}";' }
+      - {name: 'Acquire::https::Proxy', value: '"{{ idf.proxy_settings.https_proxy }}";' }
+  when:
+    idf.proxy_settings is defined
+
 - name: Reboot the machine
   shell: "sleep 5 && reboot"
   async: 1
@@ -86,4 +111,5 @@
   register: result
   until: result | succeeded
   retries: 3
+
 # vim: set ts=2 sw=2 expandtab: