formula-haproxy/haproxy/templates/haproxy.jinja

507 lines
18 KiB
Text
Raw Normal View History

# HAProxy configuration
#
# **** DO NOT EDIT THIS FILE ****
#
# This file is managed by Salt.
# 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
log /dev/log local0
log /dev/log local1 notice
user {{ salt['pillar.get']('haproxy:global:user', 'haproxy') }}
group {{ salt['pillar.get']('haproxy:global:group', 'haproxy') }}
{%- if salt['pillar.get']('haproxy:global:chroot:enable', 'no') == True %}
chroot {{ salt['pillar.get']('haproxy:global:chroot:path', '/tmp') }}
{%- endif %}
{%- if salt['pillar.get']('haproxy:global:daemon', 'no') == True %}
daemon
{%- endif %}
{%- if salt['pillar.get']('haproxy:global:stats:enable', 'no') == True %}
stats socket {{ salt['pillar.get']('haproxy:global:stats:socketpath', '/tmp/ha_stats.sock') }}
{%- endif %}
{%- if 'maxconn' in salt['pillar.get']('haproxy:global', {}) %}
maxconn {{ salt['pillar.get']('haproxy:global:maxconn') }}
{%- endif %}
{%- if 'maxpipes' in salt['pillar.get']('haproxy:global', {}) %}
maxpipes {{ salt['pillar.get']('haproxy:global:maxpipes') }}
{%- endif %}
{%- if 'spreadchecks' in salt['pillar.get']('haproxy:global', {}) %}
spread-checks {{ salt['pillar.get']('haproxy:global:spreadchecks') }}
{%- endif %}
{%- if 'tune' in salt['pillar.get']('haproxy:global', {}) %}
{{- render_list_of_dictionaries('tune', salt['pillar.get']('haproxy:global:tune'), ' ','.') }}
{%- endif %}
{%- if 'tune.ssl.default-dh-param' in salt['pillar.get']('haproxy:global', {}) %}
{{- render_list_of_dictionaries('tune.ssl.default-dh-param', salt['pillar.get']('haproxy:global:tune.ssl.default-dh-param'), ' ','.') }}
{%- endif %}
{%- if 'ca-base' in salt['pillar.get']('haproxy:global', {}) %}
{{- render_list_of_dictionaries('ca-base', salt['pillar.get']('haproxy:global:ca-base'), ' ','.') }}
{%- endif %}
{%- if 'crt-base' in salt['pillar.get']('haproxy:global', {}) %}
{{- render_list_of_dictionaries('crt-base', salt['pillar.get']('haproxy:global:crt-base'), ' ','.') }}
{%- endif %}
{%- if 'ssl-default-bind-ciphers' in salt['pillar.get']('haproxy:global', {}) %}
{{- render_list_of_dictionaries('ssl-default-bind-ciphers', salt['pillar.get']('haproxy:global:ssl-default-bind-ciphers')) }}
{%- endif %}
{%- if 'ssl-default-bind-options' in salt['pillar.get']('haproxy:global', {}) %}
{{- render_list_of_dictionaries('ssl-default-bind-options', salt['pillar.get']('haproxy:global:ssl-default-bind-options')) }}
{%- endif %}
2015-08-25 19:42:39 -04:00
2015-11-24 15:43:07 -05:00
{%- for id, userlist in salt['pillar.get']('haproxy:userlists', {})|dictsort %}
#------------------
# Global Userlists
#------------------
2015-06-08 09:16:31 -04:00
userlist {{ id }}
2015-11-24 15:43:07 -05:00
{%- for id, entry in userlist|dictsort %}
2015-06-08 10:14:28 -04:00
{%- if id == "groups" %}
2015-11-24 15:43:07 -05:00
{%- for group_name, group in entry|dictsort %}
group {{ group_name }} {{ group }}
2015-06-08 10:14:28 -04:00
{%- endfor %}
{% endif %}
{%- if id == "users" %}
2015-11-24 15:43:07 -05:00
{%- for user_name, user in entry|dictsort %}
user {{ user_name }} {{ user }}
2015-06-08 10:14:28 -04:00
{%- endfor %}
{% endif %}
2015-06-08 09:16:31 -04:00
{%- endfor %}
{% endfor %}
2015-06-08 09:16:31 -04:00
#------------------
# common defaults that all the 'listen' and 'backend' sections will
# use- if not designated in their block
#------------------
defaults
log {{ salt['pillar.get']('haproxy:defaults:log', 'global') }}
mode {{ salt['pillar.get']('haproxy:defaults:mode', 'http') }}
retries {{ salt['pillar.get']('haproxy:defaults:retries', '3') }}
balance {{ salt['pillar.get']('haproxy:defaults:balance', 'roundrobin') }}
{%- if 'monitoruri' in salt['pillar.get']('haproxy:defaults', {}) -%}
monitor-uri {{ salt['pillar.get']('haproxy:defaults:monitoruri') }}
{%- endif %}
hash-type {{ salt['pillar.get']('haproxy:defaults:hashtype', 'map-based') }}
{%- if 'options' in salt['pillar.get']('haproxy:defaults', {}) -%}
{{- render_list_of_dictionaries('option', salt['pillar.get']('haproxy:defaults:options')) }}
{%- endif %}
{%- if 'logformat' in salt['pillar.get']('haproxy:defaults', {}) %}
log-format {{ salt['pillar.get']('haproxy:defaults:logformat') }}
{%- endif %}
{%- if 'maxconn' in salt['pillar.get']('haproxy:defaults', {}) %}
maxconn {{ salt['pillar.get']('haproxy:defaults:maxconn') }}
{%- endif %}
{%- if 'timeouts' in salt['pillar.get']('haproxy:defaults', {}) %}
2015-05-23 13:43:21 -04:00
{%- for timeout in salt['pillar.get']('haproxy:defaults:timeouts') %}
timeout {{ timeout }}
{%- endfor %}
{%- else %}
timeout client 1m
timeout connect 10s
timeout server 1m
{%- 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', {}) %}
2015-11-24 15:43:07 -05:00
{%- for errorfile_name, errorfile in salt['pillar.get']('haproxy:defaults:errorfiles')|dictsort %}
errorfile {{ errorfile_name }} {{ errorfile }}
2015-05-23 13:43:21 -04:00
{%- endfor %}
{% endif %}
{%- if salt['pillar.get']('haproxy:resolvers') %}
#------------------
# DNS resolvers
#------------------
2015-11-24 15:43:07 -05:00
{%- for resolver_name, resolver in salt['pillar.get']('haproxy:resolvers', {})|dictsort %}
resolvers {{ resolver_name }}
{%- if 'options' in resolver %}
{%- for option in resolver.options %}
{{ option }}
{%- endfor %}
2015-05-23 13:43:21 -04:00
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if 'listens' in salt['pillar.get']('haproxy', {}) %}
#------------------
# listen instances
#------------------
2015-11-24 15:43:07 -05:00
{%- for listener_name, listener in salt['pillar.get']('haproxy:listens', {})|dictsort %}
listen {{ listener.get('name', listener_name) }}
{%- if 'bind' in listener %}
{%- if listener.bind is string %}
bind {{ listener.bind }}
{%- else %}
{%- for socket in listener.bind %}
bind {{ socket }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'log' in listener %}
log {{ listener.log }}
{%- endif %}
{%- if 'mode' in listener %}
mode {{ listener.mode }}
{%- endif %}
{%- if 'hashtype' in listener %}
hash-type {{ listener.hashtype }}
{%- endif %}
{%- if 'logformat' in listener %}
log-format {{ listener.logformat }}
{%- endif %}
{%- if 'uniqueidformat' in listener %}
unique-id-format {{ listener.uniqueidformat }}
{%- endif %}
{%- if 'uniqueidheader' in listener %}
unique-id-header {{ listener.uniqueidheader }}
{%- endif %}
{%- if 'sticktable' in listener %}
stick-table {{ listener.sticktable }}
{%- endif %}
{%- if 'captures' in listener %}
{%- if listener.captures is string %}
capture {{ listener.captures }}
{%- else %}
{%- for capture in listener.captures %}
capture {{ capture }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'acls' in listener %}
{%- if listener.acls is string %}
acl {{ listener.acls }}
{%- else %}
{%- for acl in listener.acls %}
acl {{ acl }}
{%- endfor %}
{%- endif %}
2015-05-23 13:43:21 -04:00
{%- endif %}
{%- if 'monitoruri' in listener %}
monitor-uri {{ listener.monitoruri }}
{%- endif %}
{%- if 'monitor' in listener %}
monitor {{ listener.monitor }}
{%- endif %}
{%- if 'tcprequests' in listener %}
{%- if listener.tcprequests is string %}
tcp-request {{ listner.tcprequests }}
{%- else %}
{%- for tcprequest in listener.tcprequests %}
tcp-request {{ tcprequest }}
{%- endfor %}
{%- endif %}
2015-07-30 18:14:36 -04:00
{%- endif %}
{%- if 'tcpresponses' in listener %}
{%- if listener.tcpresponses is string %}
tcp-response {{ listener.tcpresponses }}
{%- else %}
{%- for tcpresponse in listener.tcpresponses %}
tcp-response {{ tcpresponse }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'httprequests' in listener %}
{%- if listener.httprequests is string %}
http-request {{ listener.httprequests }}
{%- else %}
{%- for httprequest in listener.httprequests %}
http-request {{ httprequest }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'httpcheck' in listener %}
{%- if listener.httpcheck is string %}
http-check {{ listener.httpcheck }}
{%- endif %}
{%- endif %}
{%- if 'reqadds' in listener %}
{%- if listener.reqadds is string %}
reqadd {{ listener.reqadds }}
{%- else %}
{%- for reqadd in listener.reqadds %}
reqadd {{ reqadd }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'redirects' in listener %}
{%- if listener.redirects is string %}
redirect {{ listener.redirects }}
{%- else %}
{%- for redirect in listener.redirects %}
redirect {{ redirect }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'stickons' in listener %}
{%- if listener.stickons is string %}
stick on {{ listener.stickons }}
{%- else %}
{%- for stickon in listener.stickons %}
stick on {{ stickon }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'default_backend' in listener %}
default_backend {{ listener.default_backend }}
{%- endif %}
{%- if 'use_backends' in listener %}
{%- if listener.use_backends is string %}
use_backend {{ listener.use_backends }}
{%- else %}
{%- for use_backend in listener.use_backends %}
use_backend {{ use_backend }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'balance' in listener %}
balance {{ listener.balance }}
{%- endif %}
{%- if 'maxconn' in listener %}
maxconn {{ listener.maxconn }}
{%- endif %}
{%- if 'options' in listener %}
{%- if listener.options is string %}
option {{ listener.options }}
{%- else %}
{%- for option in listener.options %}
option {{ option }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'cookie' in listener %}
cookie {{ listener.cookie }}
{%- endif %}
{%- if 'stats' in listener %}
2015-11-24 15:43:07 -05:00
{%- for option, value in listener.stats|dictsort %}
{%- if option == 'enable' and value %}
stats enable
{%- else %}
stats {{ option }} {{ value }}
{%- endif %}
2015-05-23 13:43:21 -04:00
{%- endfor %}
{%- endif %}
{%- if 'appsession' in listener %}
{%- if listener.appsession is string %}
appsession {{ listener.appsession }}
{%- else %}
appsession {%- for option in listener.appsession %} {{ option }} {%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'defaultserver' in listener %}
2015-11-24 15:43:07 -05:00
default-server {%- for option, value in listener.defaultserver|dictsort %} {{ ' '.join((option, value|string, '')) }} {%- endfor %}
{%- endif %}
{%- if 'servers' in listener %}
2015-11-24 15:43:07 -05:00
{%- for server_name, server in listener.servers|dictsort %}
server {{ server.get('name', server_name) }} {{ server.host }}:{{ server.port }} {{ server.check }} {{ server.get('extra', '') }}
{%- endfor %}
{%- endif %}
{% endfor %}
{% endif %}
{%- if 'frontends' in salt['pillar.get']('haproxy', {}) %}
#------------------
# frontend instances
#------------------
2015-11-24 15:43:07 -05:00
{%- for frontend_name, frontend in salt['pillar.get']('haproxy:frontends', {})|dictsort %}
frontend {{ frontend.get('name', frontend_name) }}
{%- if 'bind' in frontend %}
{{- render_list_of_dictionaries('bind', frontend.bind) }}
{%- endif %}
{%- if 'log' in frontend %}
log {{ frontend.log }}
{%- endif %}
{%- if 'logformat' in frontend %}
log-format {{ frontend.logformat }}
{%- endif %}
{%- if 'mode' in frontend %}
mode {{ frontend.mode }}
{%- endif %}
{%- if 'maxconn' in frontend %}
maxconn {{ frontend.maxconn }}
{%- endif %}
{%- if 'options' in frontend %}
{{- render_list_of_dictionaries('option', frontend.options) }}
{%- endif %}
{%- if 'uniqueidformat' in frontend %}
unique-id-format {{ frontend.uniqueidformat }}
{%- endif %}
{%- if 'uniqueidheader' in frontend %}
2015-11-16 04:32:30 -05:00
unique-id-header {{ frontend.uniqueidheader }}
{%- endif %}
{%- if 'sticktable' in frontend %}
stick-table {{ frontend.sticktable }}
{%- endif %}
{%- if 'captures' in frontend %}
{{- render_list_of_dictionaries('capture', frontend.captures) }}
{%- endif %}
{%- if 'acls' in frontend %}
{{- render_list_of_dictionaries('acl', frontend.acls) }}
{%- endif %}
{%- if 'monitoruri' in frontend %}
monitor-uri {{ frontend.monitoruri }}
{%- endif %}
{%- if 'monitor' in frontend %}
monitor {{ frontend.monitor }}
{%- endif %}
{%- if 'tcprequests' in frontend %}
{{- render_list_of_dictionaries('tcp-request', frontend.tcprequests) }}
{%- endif %}
{%- if 'tcpresponses' in frontend %}
{{- render_list_of_dictionaries('tcp-response', frontend.tcpresponses) }}
{%- endif %}
{%- if 'httprequests' in frontend %}
{{- render_list_of_dictionaries('http-request', frontend.httprequests) }}
{%- endif %}
{%- if 'httpresponses' in frontend %}
{{- render_list_of_dictionaries('http-response', frontend.httpresponses) }}
{%- endif %}
{%- if 'rspadds' in frontend %}
{{- render_list_of_dictionaries('rspadd', frontend.rspadds) }}
{%- endif %}
{%- if 'reqadds' in frontend %}
{{- render_list_of_dictionaries('reqadd', frontend.reqadds) }}
{%- endif %}
{%- if 'redirects' in frontend %}
{{- render_list_of_dictionaries('redirect', frontend.redirects) }}
{%- endif %}
{%- if 'stickons' in frontend %}
{{- render_list_of_dictionaries('stickon', frontend.stickons) }}
{%- endif %}
{%- if 'default_backend' in frontend %}
default_backend {{ frontend.default_backend }}
{%- endif %}
{%- if 'use_backends' in frontend %}
{{- render_list_of_dictionaries('use_backend', frontend.use_backends) }}
2015-05-23 13:43:21 -04:00
{%- endif %}
{% endfor %}
{% endif %}
{%- if 'backends' in salt['pillar.get']('haproxy', {}) %}
#------------------
# backend instances
#------------------
2015-11-24 15:43:07 -05:00
{%- for backend_name, backend in salt['pillar.get']('haproxy:backends', {})|dictsort %}
backend {{ backend.get('name', backend_name) }}
{%- if 'mode' in backend %}
mode {{ backend.mode }}
{%- endif %}
{%- if 'hashtype' in backend %}
hash-type {{ backend.hashtype }}
{%- endif %}
{%- if 'balance' in backend %}
balance {{ backend.balance }}
{%- endif %}
{%- if 'options' in backend %}
{%- if backend.options is string %}
option {{ backend.options }}
{%- else %}
{%- for option in backend.options %}
option {{ option }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'sticktable' in backend %}
stick-table {{ backend.sticktable }}
{%- endif %}
{%- if 'acls' in backend %}
{{- render_list_of_dictionaries('acl', backend.acls) }}
{%- endif %}
{%- if 'tcprequests' in backend %}
{%- if backend.tcprequests is string %}
tcp-request {{ backend.tcprequests }}
{%- else %}
{%- for tcprequest in backend.tcprequests %}
tcp-request {{ tcprequest }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'tcpresponses' in backend %}
{%- if backend.tcpresponses is string %}
tcp-response {{ backend.tcpresponses }}
{%- else %}
{%- for tcpresponse in backend.tcpresponses %}
tcp-response {{ tcpresponse }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'httprequests' in backend %}
{%- if backend.httprequests is string %}
http-request {{ backend.httprequests }}
{%- else %}
{%- for httprequest in backend.httprequests %}
http-request {{ httprequest }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'httpcheck' in backend %}
{%- if backend.httpcheck is string %}
http-check {{ backend.httpcheck }}
{%- endif %}
{%- endif %}
{%- if 'redirects' in backend %}
{%- if backend.redirects is string %}
redirect {{ backend.redirects }}
{%- else %}
{%- for redirect in backend.redirects %}
redirect {{ redirect }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'stickons' in backend %}
{%- if backend.stickons is string %}
stick on {{ backend.stickons }}
{%- else %}
{%- for stickon in backend.stickons %}
stick on {{ stickon }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'cookie' in backend %}
cookie {{ backend.cookie }}
{%- endif %}
{%- if 'stats' in backend %}
2015-11-24 15:43:07 -05:00
{%- for option, value in backend.stats|dictsort %}
{%- if option == 'enable' and value %}
stats enable
{%- else %}
stats {{ option }} {{ value }}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if 'appsession' in backend %}
{%- if backend.appsession is string %}
appsession {{ backend.appsession }}
{%- else %}
appsession {%- for option in backend.appsession %} {{ option }} {%- endfor %}
2015-05-23 13:43:21 -04:00
{%- endif %}
{%- endif %}
{%- if 'reqreps' in backend %}
{{- render_list_of_dictionaries('reqrep', backend.reqreps) }}
{%- endif %}
{%- if 'defaultserver' in backend %}
2015-11-24 15:43:07 -05:00
default-server {%- for option, value in backend.defaultserver|dictsort %} {{ ' '.join((option, value|string, '')) }} {%- endfor %}
{%- endif %}
{%- if 'servers' in backend %}
2015-11-24 15:43:07 -05:00
{%- for server_name, server in backend.servers|dictsort %}
server {{ server.get('name', server_name) }} {{ server.host }}:{{ server.port }} {{ server.check }} {{ server.get('extra', '') }}
{%- endfor %}
{%- endif %}
{% endfor %}
{%- endif %}