From 44068f8d62655bca6c04ef0754a6aee06ade4254 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Wed, 4 May 2016 12:30:55 +0200
Subject: [PATCH] ansible-inventories/arocom#108 Allow support for external
 hosts in HaProxy

---
 README.md             | 4 +---
 tasks/configure.yml   | 2 +-
 templates/haproxy_cfg | 9 +++++++++
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 6265a64..8929e25 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,4 @@
-#HaProxy#
-
-##Instruction to prepare a certificate file##
+# Instruction to prepare a certificate file
 
 For HaProxy to terminate SSL requests we require a single PEM file with all certificate components chained together.
 
diff --git a/tasks/configure.yml b/tasks/configure.yml
index 4f5c7fe..e04621e 100644
--- a/tasks/configure.yml
+++ b/tasks/configure.yml
@@ -33,7 +33,7 @@
         mode=644
         state=touch
   with_items: '{{ groups.all }}'
-  notify: 'Proxy | Restart HAProxy'
+  changed_when: false
 
 - name: "Proxy | Create config file"
   template: src=haproxy_cfg
diff --git a/templates/haproxy_cfg b/templates/haproxy_cfg
index 0077d42..2f81a7a 100644
--- a/templates/haproxy_cfg
+++ b/templates/haproxy_cfg
@@ -110,6 +110,10 @@ frontend https_in_{{ cert.ip }}
   acl kibana_present hdr(host) -i -n '{{ kibana_domain|default(inventory_hostname) }}'
   use_backend backend_kibana if kibana_present
 {% endif %}
+{% for external in cert.external|default([]) %}
+  acl is_{{ external.key }} {{ external.acl }}
+  use_backend backend_{{ external.key }} if is_{{ external.key }}
+{% endfor %}
 {% if varnish_host|default(false) %}
   acl static_content path_end .jpg .jpeg .gif .png .ico .swf .css .js .htm .html
   use_backend backend_varnish if static_content
@@ -124,6 +128,11 @@ frontend https_in_{{ cert.ip }}
   use_backend backend_redirect if crm_redirect_{{host}}
 {% endif %}
 {% endfor %}
+{% for external in cert.external|default([]) %}
+
+backend backend_{{ external.key }}
+  server server_{{ external.key }} {{ external.server }} maxconn 100
+{% endfor %}
 {% endfor %}
 {% for host in groups['all'] %}
 
-- 
GitLab