From 3b51d076e3139ac46814a3800678e9df420d492a Mon Sep 17 00:00:00 2001
From: Travis Truman <travis_truman@cable.comcast.com>
Date: Mon, 27 Jun 2016 10:27:31 -0400
Subject: [PATCH] Fix HAProxy config and install version when ssl is disabled

Horizon should listen on port 80 and does not need a scheme
redirect when ssl is disabled.

We should always configure the HAProxy PPA and install the latest
version regardless of whether or not SSL is enabled or disabled.

Change-Id: I7a7d574251fe1139da0826d64958529fdf2f5b4c
Closes-Bug: #1596548
---
 playbooks/roles/haproxy_server/tasks/haproxy_install_apt.yml | 1 -
 playbooks/roles/haproxy_server/templates/service.j2          | 2 +-
 playbooks/vars/configs/haproxy_config.yml                    | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/playbooks/roles/haproxy_server/tasks/haproxy_install_apt.yml b/playbooks/roles/haproxy_server/tasks/haproxy_install_apt.yml
index 9fb376e3e2..a6533a3f82 100644
--- a/playbooks/roles/haproxy_server/tasks/haproxy_install_apt.yml
+++ b/playbooks/roles/haproxy_server/tasks/haproxy_install_apt.yml
@@ -16,7 +16,6 @@
 # NOTE(cloudnull) This can be removed when we drop 14.04 support
 - include: haproxy_add_ppa_repo.yml
   when:
-    - haproxy_ssl | bool
     - ansible_distribution_version | version_compare('16.04', '<')
 
 #TODO(evrardjp): Replace the next 2 tasks by a standard apt with cache
diff --git a/playbooks/roles/haproxy_server/templates/service.j2 b/playbooks/roles/haproxy_server/templates/service.j2
index 86e5e3d542..e799bb3b11 100644
--- a/playbooks/roles/haproxy_server/templates/service.j2
+++ b/playbooks/roles/haproxy_server/templates/service.j2
@@ -25,7 +25,7 @@
 {% endif -%}
 
 {% for vip_bind in vip_binds %}
-{% if item.service.haproxy_redirect_http_port is defined %}
+{% if item.service.haproxy_redirect_http_port is defined and item.service.haproxy_ssl %}
 {% if (loop.index == 1 or item.service.haproxy_ssl_all_vips | default(false) | bool) %}
 
 frontend {{ item.service.haproxy_service_name }}-redirect-front-{{ loop.index }}
diff --git a/playbooks/vars/configs/haproxy_config.yml b/playbooks/vars/configs/haproxy_config.yml
index ebec2ac6b6..0a07864b8d 100644
--- a/playbooks/vars/configs/haproxy_config.yml
+++ b/playbooks/vars/configs/haproxy_config.yml
@@ -161,7 +161,7 @@ haproxy_service_configs:
       haproxy_backend_nodes: "{{ groups['horizon_all'] | default([]) }}"
       haproxy_ssl: "{{ haproxy_ssl }}"
       haproxy_ssl_all_vips: true
-      haproxy_port: 443
+      haproxy_port: "{{ haproxy_ssl | ternary(443,80) }}"
       haproxy_backend_port: 80
       haproxy_redirect_http_port: 80
       haproxy_balance_type: http