From 6f87f4f52578052875d2f4a2b31b93c4483bd01f Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Thu, 10 Mar 2016 15:52:02 +0100
Subject: [PATCH] Make HaProxy to support all Drupal domains and aliases as
 well

---
 templates/haproxy_cfg   | 12 +-----------
 templates/host_list     | 10 ++++++++++
 templates/host_ssl_list | 10 ++++++++++
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/templates/haproxy_cfg b/templates/haproxy_cfg
index 7a6f7f4..8a8e1ab 100644
--- a/templates/haproxy_cfg
+++ b/templates/haproxy_cfg
@@ -52,18 +52,14 @@ frontend http-in
 {% endfor %}
 {% endfor %}
 {% for host in groups['all'] %}
-{% if hostvars[host].proxy_domains is defined %}
   acl domain_in_{{host}} hdr_dom(host) -i -f /etc/haproxy/{{host}}.list
   use_backend backend_{{host}} if domain_in_{{host}}
-{% endif %}
 {% if hostvars[host].proxy_crm_domains is defined %}
   acl crm_domain_in_{{host}} hdr_dom(host) -i -f /etc/haproxy/{{host}}.crm.list
   use_backend backend_{{host}} if crm_domain_in_{{host}}
 {% endif %}
-{% if hostvars[host].proxy_ssl_domains is defined %}
   acl redirect_ssl_{{host}} hdr_dom(host) -i -f /etc/haproxy/{{host}}.ssl.list
   use_backend backend_redirect_ssl if redirect_ssl_{{host}}
-{% endif %}
 {% endfor %}
 
 {% for cert in proxy_certificates %}
@@ -77,14 +73,10 @@ frontend https-in
 {% endfor %}
 {% endfor %}
 {% for host in groups['all'] %}
-{% if hostvars[host].proxy_ssl_domains is defined %}
   acl ssl_domain_in_{{host}} hdr_dom(host) -i -f /etc/haproxy/{{host}}.ssl.list
   use_backend backend_{{host}} if ssl_domain_in_{{host}}
-{% endif %}
-{% if hostvars[host].proxy_domains is defined %}
   acl redirect_{{host}} hdr_dom(host) -i -f /etc/haproxy/{{host}}.list
   use_backend backend_redirect if redirect_{{host}}
-{% endif %}
 {% if hostvars[host].proxy_crm_domains is defined %}
   acl crm_redirect_{{host}} hdr_dom(host) -i -f /etc/haproxy/{{host}}.list
   use_backend backend_redirect if crm_redirect_{{host}}
@@ -93,11 +85,9 @@ frontend https-in
 {% endfor %}
 
 {% for host in groups['all'] %}
-{% if (hostvars[host].proxy_domains is defined) or (hostvars[host].proxy_ssl_domains is defined) or (hostvars[host].proxy_crm_domains is defined) %}
 backend backend_{{host}}
-  server server_{{host}} {{hostvars[host]['ansible_default_ipv4']['address']|default(hostvars[host]['static_ipv4'])}}:80 maxconn 32
+  server server_{{host}} {{hostvars[host]['static_ipv4']|default(hostvars[host]['ansible_default_ipv4']['address'])}}:80 maxconn 32
 
-{% endif %}
 {% endfor %}
 
 backend backend_redirect_ssl
diff --git a/templates/host_list b/templates/host_list
index 56d67eb..2ebc16e 100644
--- a/templates/host_list
+++ b/templates/host_list
@@ -1,3 +1,13 @@
 {% for domain in hostvars[item].proxy_domains|default([]) %}
 {{domain}}
 {% endfor %}
+{% for drupal in hostvars[item].drupal_settings|default([]) %}
+{% for domain in drupal.domains|default([]) %}
+{% if domain.protocol|default('https') == 'http' %}
+{{domain.domain}}
+{% for alias in domain.aliases|default([]) %}
+{{alias}}
+{% endfor %}
+{% endif %}
+{% endfor %}
+{% endfor %}
diff --git a/templates/host_ssl_list b/templates/host_ssl_list
index ee5bc3f..f51782b 100644
--- a/templates/host_ssl_list
+++ b/templates/host_ssl_list
@@ -1,3 +1,13 @@
 {% for domain in hostvars[item].proxy_ssl_domains|default([]) %}
 {{domain}}
 {% endfor %}
+{% for drupal in hostvars[item].drupal_settings|default([]) %}
+{% for domain in drupal.domains|default([]) %}
+{% if domain.protocol|default('https') == 'https' %}
+{{domain.domain}}
+{% for alias in domain.aliases|default([]) %}
+{{alias}}
+{% endfor %}
+{% endif %}
+{% endfor %}
+{% endfor %}
-- 
GitLab