Merge pull request #11 from bigbosst/defaults-and-naming

Defaults, Naming, and Multiple Binds
This commit is contained in:
Forrest 2015-07-13 20:24:24 -07:00
commit c351a70e00
2 changed files with 29 additions and 10 deletions

View file

@ -33,6 +33,7 @@ defaults
log {{ salt['pillar.get']('haproxy:defaults:log') }} log {{ salt['pillar.get']('haproxy:defaults:log') }}
mode {{ salt['pillar.get']('haproxy:defaults:mode') }} mode {{ salt['pillar.get']('haproxy:defaults:mode') }}
retries {{ salt['pillar.get']('haproxy:defaults:retries') }} retries {{ salt['pillar.get']('haproxy:defaults:retries') }}
balance {{ salt['pillar.get']('haproxy:defaults:balance', 'roundrobin') }}
{%- 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 }} option {{ option }}
@ -57,7 +58,7 @@ defaults
#--------------------------------------------------------------------- #---------------------------------------------------------------------
{%- if 'frontends' in salt['pillar.get']('haproxy', {}) %} {%- if 'frontends' in salt['pillar.get']('haproxy', {}) %}
{%- 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].get(name, frontend[0]) }}
bind {{ frontend[1].bind }} bind {{ frontend[1].bind }}
{%- if 'redirects' in frontend[1] %} {%- if 'redirects' in frontend[1] %}
{%- for front_redirect in frontend[1].redirects %} {%- for front_redirect in frontend[1].redirects %}
@ -89,12 +90,14 @@ redirect {{ front_redirect }}
#--------------------------------------------------------------------- #---------------------------------------------------------------------
{%- if 'backends' in salt['pillar.get']('haproxy', {}) %} {%- if 'backends' in salt['pillar.get']('haproxy', {}) %}
{%- for backend in salt['pillar.get']('haproxy:backends', {}).iteritems() %} # Backend loop start {%- for backend in salt['pillar.get']('haproxy:backends', {}).iteritems() %} # Backend loop start
backend {{ backend[1].name }} backend {{ backend[1].get(name, backend[0]) }}
{%- if 'redirects' in backend[1] %} {%- if 'redirects' in backend[1] %}
{%- for redirect in backend[1].redirects %} # Redirect loop start {%- for redirect in backend[1].redirects %} # Redirect loop start
redirect {{ redirect }}{% endfor %} redirect {{ redirect }}{% endfor %}
{%- endif %} {%- endif %}
{%- if 'balance' in backend[1] %}
balance {{ backend[1].balance }} balance {{ backend[1].balance }}
{%- endif %}
{%- if 'options' in backend[1] %} {%- if 'options' in backend[1] %}
{%- for option in backend[1].options %} {%- for option in backend[1].options %}
option {{ option }} option {{ option }}
@ -114,7 +117,7 @@ redirect {{ redirect }}{% endfor %}
{%- endif %} {%- endif %}
{%- if 'servers' in backend[1] %} {%- if 'servers' in backend[1] %}
{%- 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].get(name,server[0]) }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }}{% endfor %}
{% endif %} {% endif %}
{% endfor %} # Backend loop end {% endfor %} # Backend loop end
{% endif %} {% endif %}

View file

@ -53,8 +53,7 @@ haproxy:
- "X-Forwarded-Proto:\\ http" - "X-Forwarded-Proto:\\ http"
default_backend: www-backend default_backend: www-backend
frontend2: www-https:
name: www-https
bind: "*:443 ssl crt /etc/ssl/private/certificate-chain-and-key-combined.pem" bind: "*:443 ssl crt /etc/ssl/private/certificate-chain-and-key-combined.pem"
reqadd: reqadd:
- "X-Forwarded-Proto:\\ https" - "X-Forwarded-Proto:\\ https"
@ -63,7 +62,12 @@ haproxy:
- url_static path_beg -i /static /images /javascript /stylesheets - url_static path_beg -i /static /images /javascript /stylesheets
- url_static path_end -i .jpg .gif .png .css .js - url_static path_end -i .jpg .gif .png .css .js
use_backends: use_backends:
- static if url_static - static-backend if url_static
some-services:
bind:
- "*:8080"
- "*:8088"
default_backend: api-backend
backends: backends:
backend1: backend1:
@ -76,8 +80,7 @@ haproxy:
host: 192.168.1.213 host: 192.168.1.213
port: 80 port: 80
check: check check: check
backend2: static-backend:
name: static
balance: roundrobin balance: roundrobin
redirect: scheme https if !{ ssl_fc } redirect: scheme https if !{ ssl_fc }
options: options:
@ -92,8 +95,21 @@ haproxy:
realm: LoadBalancer realm: LoadBalancer
auth: "user:password" auth: "user:password"
servers: servers:
server1: some-server:
name: some-server
host: 123.156.189.111 host: 123.156.189.111
port: 8080 port: 8080
check: check check: check
api-backend:
options:
- http-server-close
- forwardfor
servers:
apiserver1:
host: apiserver1.example.com
port: 80
check: check
server2:
name: apiserver2
host: apiserver2.example.com
port: 80
check: check