CORD-993
elasticstack role, installs on head node
fix elasticstack/java apt-cacher passthrough
reliability fix for download Glance VM images
more reliable reliability fix
simplify apt-cacher ssl passthrough
apt-cacher defaults in other roles

Change-Id: Ia78d256f562c30539240d12ba163f7af6e375131
diff --git a/roles/apache-proxy/files/cord-http.conf b/roles/apache-proxy/files/cord-http.conf
new file mode 100644
index 0000000..d8393b1
--- /dev/null
+++ b/roles/apache-proxy/files/cord-http.conf
@@ -0,0 +1,68 @@
+<IfModule proxy_module>
+    ProxyPreserveHost on
+
+    # Map /fabric to the onos instance that is controlling the leaf
+    #     spine fabric
+    <Location /fabric/>
+        ProxyPass http://onos-fabric:8181/
+        ProxyPassReverse http://onos-fabric:8181/
+        ProxyPassReverseCookiePath  "/"  "/fabric/"
+        Header edit Location "(^http[s]?://[^/]*)(\.*)" "$1/fabric$2"
+    </Location>
+    <Location /fabric/onos/ui/websock/>
+        ProxyPass "ws://onos-fabric:8181/onos/ui/websock/" disablereuse=on
+    </Location>
+
+    # kibana/elasticsearch
+    <Location /kibana>
+      ProxyPass http://localhost:5601
+      ProxyPassReverse http://localhost:5601
+    </Location>
+
+    # Map /vtn to the onos instance that is controller the cordvtn
+    #     application
+    <Location /vtn/>
+        ProxyPass http://onos-cord:8182/
+        ProxyPassReverse http://onos-cord:8182/
+        ProxyPassReverseCookiePath  "/"  "/vtn/"
+        Header edit Location "(^http[s]?://[^/]*)(\.*)" "$1/vtn$2"
+    </Location>
+
+    <Location /vtn/onos/ui/websock/>
+        ProxyPass "ws://onos-cord:8182/onos/ui/websock/" disablereuse=on
+    </Location>
+
+    # Cord SPA and rest-gw
+    ProxyPass /spa http://xos-spa-gui:4000
+    ProxyPass /spa/socket.io http://xos-rest-gw:3000/socket.io
+    ProxyPass /socket.io http://xos-rest-gw:3000/socket.io
+    <Location /socket.io>
+        RewriteEngine on
+        RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
+        RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
+        RewriteRule .* ws://xos-rest-gw:3000%{REQUEST_URI} [P]
+    </Location>
+    
+    # Map the various XOS roots to the XOS instance
+    ProxyPass /xos http://xos:9000
+    ProxyPass /xos/ http://xos:9000/
+    ProxyPassMatch /(api)$ http://xos:9000/$1/
+    ProxyPass /api/ http://xos:9000/api/
+    ProxyPass /login http://xos:9000/login
+    ProxyPass /admin/ http://xos:9000/admin/
+    ProxyPass /static/ http://xos:9000/static/
+    ProxyPass /loggedin/ http://xos:9000/loggedin/
+    ProxyPass /serviceGrid/ http://xos:9000/serviceGrid/
+
+    ProxyPass /xosapi/ http://xos-chameleon:9101/xosapi/
+</IfModule>
+
+<IfModule rewrite_module>
+    RewriteEngine On
+    # Redirect (permanently) requests for /MAAS to /MAAS/.
+    RewriteRule ^/MAAS$ %{REQUEST_URI}/ [R=301,L]
+</IfModule>
+
+# Redirects so that basic URLs entered go the right place
+Redirect /fabric /fabric/onos/ui
+Redirect /vtn /vtn/onos/ui
diff --git a/roles/apache-proxy/handlers/main.yml b/roles/apache-proxy/handlers/main.yml
new file mode 100644
index 0000000..42875a0
--- /dev/null
+++ b/roles/apache-proxy/handlers/main.yml
@@ -0,0 +1,8 @@
+---
+# apache-proxy/handlers/main.yml
+
+- name: reload apache2
+  become: yes
+  service:
+    name: apache2
+    state: reloaded
diff --git a/roles/apache-proxy/tasks/main.yml b/roles/apache-proxy/tasks/main.yml
new file mode 100644
index 0000000..ccfdfae
--- /dev/null
+++ b/roles/apache-proxy/tasks/main.yml
@@ -0,0 +1,38 @@
+---
+# apache-proxy/tasks/main.yml
+
+- name: Install Apache
+  apt:
+    name: "{{ item }}"
+    update_cache: yes
+    cache_valid_time: 3600
+  with_items:
+    - apache2
+    - apache2-utils
+
+- name: Enable Apache2 Modules
+  apache2_module:
+    name: "{{ item }}"
+  notify: reload apache2
+  with_items:
+    - proxy
+    - proxy_http
+    - proxy_wstunnel
+    - rewrite
+    - headers
+
+- name: Apache configuration for CORD sites
+  copy:
+    src: files/cord-http.conf
+    dest: /etc/apache2/conf-available/cord-http.conf
+    owner: root
+    group: root
+    mode: 0644
+  notify: reload apache2
+
+- name: Enable CORD Apache Configuration
+  command: a2enconf cord-http
+  register: en_cord_http
+  changed_when: en_cord_http.stdout.find('already enabled') == -1
+  notify: reload apache2
+