Merge pull request #8 from johnkeates/master

Better redirect support, now without typo's! (yes, that is an intended pun)
This commit is contained in:
Nitin Madhok 2015-05-25 12:42:00 -04:00
commit e00b5907d0
4 changed files with 62 additions and 37 deletions

View file

@ -55,6 +55,7 @@ Currently, only a handful of options can be set using the pillar:
+ name: the name haproxy will use for the frontend + name: the name haproxy will use for the frontend
+ bind: the bind string: this allows you to set the IP, Port and other paramters for the bind + bind: the bind string: this allows you to set the IP, Port and other paramters for the bind
+ redirect: add a redirect line, an unparsed string like in the backend
+ reqadd: an array of reqadd statements. Looped over and put in the configuration, no parsing + reqadd: an array of reqadd statements. Looped over and put in the configuration, no parsing
+ default_backend: sets the default backend + default_backend: sets the default backend
+ acls: a list of acls, not parsed, simply looped and put in to the configuration + acls: a list of acls, not parsed, simply looped and put in to the configuration

View file

@ -1,3 +1,14 @@
# Because on Ubuntu we don't have a current HAProxy in the usual repo, we add a PPA
{% if salt['grains.get']('osfullname') == 'Ubuntu' %}
haproxy_ppa_repo:
pkgrepo.managed:
- ppa: vbernat/haproxy-1.5
- require_in:
- pkg: haproxy.install
- watch_in:
- pkg: haproxy.install
{% endif %}
haproxy.install: haproxy.install:
pkg.installed: pkg.installed:
- name: haproxy - name: haproxy

View file

@ -35,15 +35,18 @@ defaults
retries {{ salt['pillar.get']('haproxy:defaults:retries') }} retries {{ salt['pillar.get']('haproxy:defaults:retries') }}
{%- if 'options' in salt['pillar.get']('haproxy:defaults', {}) %} {%- if 'options' in salt['pillar.get']('haproxy:defaults', {}) %}
{%- for option in salt['pillar.get']('haproxy:defaults:options') %} {%- for option in salt['pillar.get']('haproxy:defaults:options') %}
option {{ option }}{% endfor %} option {{ option }}
{%- endfor %}
{% endif %} {% endif %}
{%- if 'timeouts' in salt['pillar.get']('haproxy:defaults', {}) %} {%- if 'timeouts' in salt['pillar.get']('haproxy:defaults', {}) %}
{%- for timeout in salt['pillar.get']('haproxy:defaults:timeouts') %} {%- for timeout in salt['pillar.get']('haproxy:defaults:timeouts') %}
timeout {{ timeout }}{% endfor %} timeout {{ timeout }}
{%- endfor %}
{% endif %} {% endif %}
{%- if 'errorfiles' in salt['pillar.get']('haproxy:defaults', {}) %} {%- if 'errorfiles' in salt['pillar.get']('haproxy:defaults', {}) %}
{%- for errorfile in salt['pillar.get']('haproxy:defaults:errorfiles').iteritems() %} {%- for errorfile in salt['pillar.get']('haproxy:defaults:errorfiles').iteritems() %}
errorfile {{ errorfile[0] }} {{ errorfile[1] }}{% endfor %} errorfile {{ errorfile[0] }} {{ errorfile[1] }}
{%- endfor %}
{% endif %} {% endif %}
@ -56,6 +59,11 @@ defaults
{%- for frontend in salt['pillar.get']('haproxy:frontends', {}).iteritems() %} {%- for frontend in salt['pillar.get']('haproxy:frontends', {}).iteritems() %}
frontend {{ frontend[1].name }} frontend {{ frontend[1].name }}
bind {{ frontend[1].bind }} bind {{ frontend[1].bind }}
{%- if 'redirects' in frontend[1] %}
{%- for front_redirect in frontend[1].redirects %}
redirect {{ front_redirect }}
{% endfor %}
{%- endif %}
{%- if 'acls' in frontend[1] %} {%- if 'acls' in frontend[1] %}
{%- for acl in frontend[1].acls %} {%- for acl in frontend[1].acls %}
acl {{ acl }} acl {{ acl }}
@ -80,8 +88,12 @@ frontend {{ frontend[1].name }}
# backend instances # backend instances
#--------------------------------------------------------------------- #---------------------------------------------------------------------
{%- if 'backends' in salt['pillar.get']('haproxy', {}) %} {%- if 'backends' in salt['pillar.get']('haproxy', {}) %}
{%- for backend in salt['pillar.get']('haproxy:backends', {}).iteritems() %} {%- for backend in salt['pillar.get']('haproxy:backends', {}).iteritems() %} # Backend loop start
backend {{ backend[1].name }} backend {{ backend[1].name }}
{%- if 'redirects' in backend[1] %}
{%- for redirect in backend[1].redirects %} # Redirect loop start
redirect {{ redirect }}{% endfor %}
{%- endif %}
balance {{ backend[1].balance }} balance {{ backend[1].balance }}
{%- if 'options' in backend[1] %} {%- if 'options' in backend[1] %}
{%- for option in backend[1].options %} {%- for option in backend[1].options %}
@ -104,5 +116,5 @@ backend {{ backend[1].name }}
{%- for server in backend[1].servers.iteritems() %} {%- for server in backend[1].servers.iteritems() %}
server {{ server[1].name }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }}{% endfor %} server {{ server[1].name }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }}{% endfor %}
{% endif %} {% endif %}
{% endfor %} {% endfor %} # Backend loop end
{% endif %} {% endif %}

View file

@ -48,6 +48,7 @@ haproxy:
frontend1: frontend1:
name: www-http name: www-http
bind: "*:80" bind: "*:80"
redirect: scheme https if !{ ssl_fc }
reqadd: reqadd:
- "X-Forwarded-Proto:\\ http" - "X-Forwarded-Proto:\\ http"
default_backend: www-backend default_backend: www-backend