Add stats. Add reqrep to backend. Add macro for template simplification. Add example pillars

This commit is contained in:
Barrie Campbell 2015-08-17 16:40:55 -04:00
parent 62ee258814
commit 81ab45bed3
2 changed files with 45 additions and 111 deletions

View file

@ -5,6 +5,19 @@
# This file is managed by Salt. # This file is managed by Salt.
# Any changes will be overwritten. # Any changes will be overwritten.
{%- macro render_list_of_dictionaries(name, list, indent = ' ', infix = ' ', postfix = '\t') %}
{%- if list is not iterable or list is string %}
{{ indent ~ name ~ postfix ~ list }}
{%- else %}{% for item in list %}
{%- if item is not iterable or item is string %}
{{ indent ~ name ~ postfix ~ item }}
{%- else %}{% for key, value in item.items() %}
{{- render_list_of_dictionaries(indent ~ name ~ infix ~ key, value, '', infix, postfix) }}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endmacro %}
#------------------ #------------------
# Global settings # Global settings
@ -33,28 +46,14 @@ global
spread-checks {{ salt['pillar.get']('haproxy:global:spreadchecks') }} spread-checks {{ salt['pillar.get']('haproxy:global:spreadchecks') }}
{%- endif %} {%- endif %}
{%- if 'tune' in salt['pillar.get']('haproxy:global', {}) %} {%- if 'tune' in salt['pillar.get']('haproxy:global', {}) %}
{%- for setting, item in salt['pillar.get']('haproxy:global:tune').iteritems() %} {{- render_list_of_dictionaries('tune', salt['pillar.get']('haproxy:global:tune'), ' ','.') }}
{%- if item is number or item is string %}
tune.{{setting}} {{item}}
{%- else %}
{%- for subsetting, value in item.iteritems() %}
tune.{{setting}}.{{subsetting}} {{value}}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endif %} {%- endif %}
{%- if 'ssl-default-bind-ciphers' in salt['pillar.get']('haproxy:global', {}) %} {%- if 'ssl-default-bind-ciphers' in salt['pillar.get']('haproxy:global', {}) %}
ssl-default-bind-ciphers {{ salt['pillar.get']('haproxy:global:ssl-default-bind-ciphers') }} {{- render_list_of_dictionaries('ssl-default-bind-ciphers', salt['pillar.get']('haproxy:global:ssl-default-bind-ciphers')) }}
{%- endif %} {%- endif %}
{%- if 'ssl-default-bind-options' in salt['pillar.get']('haproxy:global', {}) %} {%- if 'ssl-default-bind-options' in salt['pillar.get']('haproxy:global', {}) %}
{%- if salt['pillar.get']('haproxy:global:ssl-default-bind-options') is string or salt['pillar.get']('haproxy:global:ssl-default-bind-options') is number %} {{- render_list_of_dictionaries('ssl-default-bind-options', salt['pillar.get']('haproxy:global:ssl-default-bind-options')) }}
ssl-default-bind-options {{ salt['pillar.get']('haproxy:global:ssl-default-bind-options') }} {%- endif %}
{%- else %}
{%- for option in salt['pillar.get']('haproxy:global:ssl-default-bind-options').items() %}
ssl-default-bind-options {{ option }}
{%- endfor %}
{%- endif %}
{% endif %}
#------------------ #------------------
# common defaults that all the 'listen' and 'backend' sections will # common defaults that all the 'listen' and 'backend' sections will
@ -65,14 +64,8 @@ defaults
mode {{ salt['pillar.get']('haproxy:defaults:mode', 'http') }} mode {{ salt['pillar.get']('haproxy:defaults:mode', 'http') }}
retries {{ salt['pillar.get']('haproxy:defaults:retries', '3') }} retries {{ salt['pillar.get']('haproxy:defaults:retries', '3') }}
balance {{ salt['pillar.get']('haproxy:defaults:balance', 'roundrobin') }} balance {{ salt['pillar.get']('haproxy:defaults:balance', 'roundrobin') }}
{%- if 'options' in salt['pillar.get']('haproxy:defaults', {}) %} {%- if 'options' in salt['pillar.get']('haproxy:defaults', {}) -%}
{%- if salt['pillar.get']('haproxy:defaults:options') is string %} {{- render_list_of_dictionaries('option', salt['pillar.get']('haproxy:defaults:options')) }}
option {{ salt['pillar.get']('haproxy:defaults:options') }}
{%- else %}
{%- for option in salt['pillar.get']('haproxy:defaults:options') %}
option {{ option }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'maxconn' in salt['pillar.get']('haproxy:defaults', {}) %} {%- if 'maxconn' in salt['pillar.get']('haproxy:defaults', {}) %}
maxconn {{ salt['pillar.get']('haproxy:defaults:maxconn') }} maxconn {{ salt['pillar.get']('haproxy:defaults:maxconn') }}
@ -86,6 +79,9 @@ defaults
timeout connect 10s timeout connect 10s
timeout server 1m timeout server 1m
{%- endif %} {%- endif %}
{%- if 'stats' in salt['pillar.get']('haproxy:defaults', {}) -%}
{{ render_list_of_dictionaries('stats', salt['pillar.get']('haproxy:defaults:stats')) }}
{%- 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] }} errorfile {{ errorfile[0] }} {{ errorfile[1] }}
@ -216,7 +212,7 @@ listen {{ listener[1].get('name', listener[0]) }}
{%- if listener[1].use_backends is string %} {%- if listener[1].use_backends is string %}
use_backend {{ listener[1].use_backends }} use_backend {{ listener[1].use_backends }}
{%- else %} {%- else %}
{%- for use_backend in listener[1].use_backendsi %} {%- for use_backend in listener[1].use_backends %}
use_backend {{ use_backend }} use_backend {{ use_backend }}
{%- endfor %} {%- endfor %}
{%- endif %} {%- endif %}
@ -273,13 +269,7 @@ listen {{ listener[1].get('name', listener[0]) }}
{%- for frontend in salt['pillar.get']('haproxy:frontends', {}).iteritems() %} {%- for frontend in salt['pillar.get']('haproxy:frontends', {}).iteritems() %}
frontend {{ frontend[1].get('name', frontend[0]) }} frontend {{ frontend[1].get('name', frontend[0]) }}
{%- if 'bind' in frontend[1] %} {%- if 'bind' in frontend[1] %}
{%- if frontend[1].bind is string %} {{- render_list_of_dictionaries('bind', frontend[1].bind) }}
bind {{ frontend[1].bind }}
{%- else %}
{%- for socket in frontend[1].bind %}
bind {{ socket }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'log' in frontend[1] %} {%- if 'log' in frontend[1] %}
log {{ frontend[1].log }} log {{ frontend[1].log }}
@ -291,13 +281,7 @@ frontend {{ frontend[1].get('name', frontend[0]) }}
maxconn {{ frontend[1].maxconn }} maxconn {{ frontend[1].maxconn }}
{%- endif %} {%- endif %}
{%- if 'options' in frontend[1] %} {%- if 'options' in frontend[1] %}
{%- if frontend[1].options is string %} {{- render_list_of_dictionaries('options', frontend[1].options) }}
option {{ frontend[1].options }}
{%- else %}
{%- for option in frontend[1].options %}
option {{ option }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'uniqueidformat' in frontend[1] %} {%- if 'uniqueidformat' in frontend[1] %}
unique-id-format {{ frontend[1].uniqueidformat }} unique-id-format {{ frontend[1].uniqueidformat }}
@ -309,88 +293,34 @@ frontend {{ frontend[1].get('name', frontend[0]) }}
stick-table {{ frontend[1].sticktable }} stick-table {{ frontend[1].sticktable }}
{%- endif %} {%- endif %}
{%- if 'captures' in frontend[1] %} {%- if 'captures' in frontend[1] %}
{%- if frontend[1].captures is string %} {{- render_list_of_dictionaries('capture', frontend[1].captures) }}
capture {{ frontend[1].captures }}
{%- else %}
{%- for capture in frontend[1].captures %}
capture {{ capture }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'acls' in frontend[1] %} {%- if 'acls' in frontend[1] %}
{%- if frontend[1].acls is string %} {{- render_list_of_dictionaries('acl', frontend[1].acls) }}
acl {{ frontend[1].acls }}
{%- else %}
{%- for acl in frontend[1].acls %}
acl {{ acl }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'tcprequests' in frontend[1] %} {%- if 'tcprequests' in frontend[1] %}
{%- if frontend[1].tcprequests is string %} {{- render_list_of_dictionaries('tcp-request', frontend[1].tcprequests) }}
tcp-request {{ frontend[1].tcprequests }}
{%- else %}
{%- for tcprequest in frontend[1].tcprequests %}
tcp-request {{ tcprequest }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'tcpresponses' in frontend[1] %} {%- if 'tcpresponses' in frontend[1] %}
{%- if frontend[1].tcpresponses is string %} {{- render_list_of_dictionaries('tcp-response', frontend[1].tcpresponses) }}
tcp-response {{ frontend[1].tcpresponses }}
{%- else %}
{%- for tcpresponse in frontend[1].tcpresponses %}
tcp-response {{ tcpresponse }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'httprequests' in frontend[1] %} {%- if 'httprequests' in frontend[1] %}
{%- if frontend[1].httprequests is string %} {{- render_list_of_dictionaries('http-request', frontend[1].httprequests) }}
http-request {{ frontend[1].httprequests }}
{%- else %}
{%- for httprequest in frontend[1].httprequests %}
http-request {{ httprequest }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'reqadds' in frontend[1] %} {%- if 'reqadds' in frontend[1] %}
{%- if frontend[1].reqadds is string %} {{- render_list_of_dictionaries('reqadd', frontend[1].reqadds) }}
reqadd {{ frontend[1].reqadds }}
{%- else %}
{%- for reqadd in frontend[1].reqadds %}
reqadd {{ reqadd }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'redirects' in frontend[1] %} {%- if 'redirects' in frontend[1] %}
{%- if frontend[1].redirects is string %} {{- render_list_of_dictionaries('redirect', frontend[1].redirects) }}
redirect {{ frontend[1].redirects }}
{%- else %}
{%- for redirect in frontend[1].redirects %}
redirect {{ redirect }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'stickons' in frontend[1] %} {%- if 'stickons' in frontend[1] %}
{%- if frontend[1].stickons is string %} {{- render_list_of_dictionaries('stickon', frontend[1].stickons) }}
stick on {{ frontend[1].stickons }}
{%- else %}
{%- for stickon in frontend[1].stickons %}
stick on {{ stickon }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'default_backend' in frontend[1] %} {%- if 'default_backend' in frontend[1] %}
default_backend {{ frontend[1].default_backend }} default_backend {{ frontend[1].default_backend }}
{%- endif %} {%- endif %}
{%- if 'use_backends' in frontend[1] %} {%- if 'use_backends' in frontend[1] %}
{%- if frontend[1].use_backends is string %} {{- render_list_of_dictionaries('use_backend', frontend[1].use_backends) }}
use_backend {{ frontend[1].use_backends }}
{%- else %}
{%- for use_backend in frontend[1].use_backends %}
use_backend {{ use_backend }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
@ -420,13 +350,7 @@ backend {{ backend[1].get('name',backend[0]) }}
stick-table {{ backend[1].sticktable }} stick-table {{ backend[1].sticktable }}
{%- endif %} {%- endif %}
{%- if 'acls' in backend[1] %} {%- if 'acls' in backend[1] %}
{%- if backend[1].acls is string %} {{- render_list_of_dictionaries('acl', backend[1].acls) }}
acl {{ backend[1].acls }}
{%- else %}
{%- for acl in backend[1].acls %}
acl {{ acl }}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- if 'tcprequests' in backend[1] %} {%- if 'tcprequests' in backend[1] %}
{%- if backend[1].tcprequests is string %} {%- if backend[1].tcprequests is string %}
@ -492,6 +416,9 @@ backend {{ backend[1].get('name',backend[0]) }}
appsession {%- for option in backend[1].appsession %} {{ option }} {%- endfor %} appsession {%- for option in backend[1].appsession %} {{ option }} {%- endfor %}
{%- endif %} {%- endif %}
{%- endif %} {%- endif %}
{%- if 'reqreps' in backend[1] %}
{{- render_list_of_dictionaries('reqrep', backend[1].reqreps) }}
{%- endif %}
{%- if 'defaultserver' in backend[1] %} {%- if 'defaultserver' in backend[1] %}
default-server {%- for option, value in backend[1].defaultserver.iteritems() %} {{ ' '.join((option, value|string, '')) }} {%- endfor %} default-server {%- for option, value in backend[1].defaultserver.iteritems() %} {{ ' '.join((option, value|string, '')) }} {%- endfor %}
{%- endif %} {%- endif %}

View file

@ -37,6 +37,11 @@ haproxy:
- server 1m - server 1m
- http-keep-alive 10s - http-keep-alive 10s
- check 10s - check 10s
stats:
- enable
- uri: '/admin?stats'
- realm: 'Haproxy\ Statistics'
- auth: 'admin1:AdMiN123'
errorfiles: errorfiles:
400: /etc/haproxy/errors/400.http 400: /etc/haproxy/errors/400.http
@ -171,4 +176,6 @@ haproxy:
- "content accept if serverhello" - "content accept if serverhello"
stickons: stickons:
- "payload_lv(43,1) if clienthello" - "payload_lv(43,1) if clienthello"
reqrep:
- "^([^\ :]*)\ /static/(.*) \1\ \2"
options: "ssl-hello-chk" options: "ssl-hello-chk"