formula-haproxy/haproxy/templates/haproxy.jinja

193 lines
7 KiB
Text
Raw Normal View History

# HAProxy configuration
#
# **** DO NOT EDIT THIS FILE ****
#
# This file is managed by Salt.
# Any changes will be overwritten.
#---------------------------------------------------------------------
# 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 %}
2015-05-23 13:43:21 -04:00
# Stats support is currently limited to socket mode
stats socket {{ salt['pillar.get']('haproxy:global:stats:socketpath', '/tmp/ha_stats.sock') }}
2015-05-23 13:43:21 -04:00
{% endif %}
#---------------------------------------------------------------------
# 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') }}
mode {{ salt['pillar.get']('haproxy:defaults:mode') }}
retries {{ salt['pillar.get']('haproxy:defaults:retries') }}
balance {{ salt['pillar.get']('haproxy:defaults:balance', 'roundrobin') }}
{%- if 'options' in salt['pillar.get']('haproxy:defaults', {}) %}
2015-05-23 13:43:21 -04:00
{%- for option in salt['pillar.get']('haproxy:defaults:options') %}
option {{ option }}
{%- endfor %}
{% 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 %}
{% endif %}
{%- if 'errorfiles' in salt['pillar.get']('haproxy:defaults', {}) %}
2015-05-23 13:43:21 -04:00
{%- for errorfile in salt['pillar.get']('haproxy:defaults:errorfiles').iteritems() %}
errorfile {{ errorfile[0] }} {{ errorfile[1] }}
{%- endfor %}
{% endif %}
#---------------------------------------------------------------------
# listen instances
#---------------------------------------------------------------------
{%- if 'listens' in salt['pillar.get']('haproxy', {}) %}
{%- for listener in salt['pillar.get']('haproxy:listens', {}).iteritems() %}
listen {{ listener[1].get(name, listener[0]) }}
{%- if 'bind' in listener[1] %}
{%- for socket in listener[1].bind %}
bind {{ socket }}
{%- endfor %}
{%- endif %}
{%- if 'redirects' in listener[1] %}
{%- for front_redirect in listener[1].redirects %}
redirect {{ front_redirect }}
{% endfor %}
{%- endif %}
{%- if 'acls' in listener[1] %}
{%- for acl in listener[1].acls %}
acl {{ acl }}
{%- endfor %}
{%- endif %}
{%- if 'reqadd' in listener[1] %}
{%- for reqadd in listener[1].reqadd %}
reqadd {{ reqadd }}
{%- endfor %}
{%- endif %}
{%-if 'default_backend' in listener[1] -%}
default_backend {{ listener[1].default_backend }}
{%- endif %}
{%-if 'use_backends' in listener[1] -%}
{%- for use_backend in listener[1].use_backends %}
use_backend {{ use_backend }}
{% endfor %}
{%- endif %}
{%- if 'balance' in listener[1] %}
balance {{ listener[1].balance }}
{%- endif %}
{%- if 'options' in listener[1] %}
{%- for option in listener[1].options %}
option {{ option }}
{%- endfor %}
{%- endif %}
{%- if 'cookie' in listener[1] %}
cookie {{ listener[1].cookie }}
{%- endif %}
{%- if 'stats' in listener[1] %}
{%- for option, value in listener[1].stats.iteritems() %}
{%- if option == 'enable' and value %}
stats enable
{%- else %}
stats {{ option }} {{ value }}
{%- endif %}
{%- endfor %}
2015-07-17 23:36:15 -04:00
{f 'defaultserver' in listener[1] %}
default-server {% for option, value in listener[1].defaultserver.iteritems() -%} {{ ' '.join((option,value|string)) }} {%- endfor %}
{% endif %}%- endif %}
{%- if 'servers' in listener[1] %}
{%- for server in listener[1].servers.iteritems() %}
server {{ server[1].get(name,server[0]) }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
#---------------------------------------------------------------------
# frontend instances
#---------------------------------------------------------------------
{%- if 'frontends' in salt['pillar.get']('haproxy', {}) %}
2015-05-23 13:43:21 -04:00
{%- for frontend in salt['pillar.get']('haproxy:frontends', {}).iteritems() %}
frontend {{ frontend[1].get(name, frontend[0]) }}
{%- if 'bind' in frontend[1] %}
{%- for socket in frontend[1].bind %}
bind {{ socket }}
{%- endfor %}
{%- endif %}
2015-05-23 13:43:21 -04:00
{%- if 'redirects' in frontend[1] %}
{%- for front_redirect in frontend[1].redirects %}
2015-05-17 12:26:08 -04:00
redirect {{ front_redirect }}
2015-05-23 13:43:21 -04:00
{% endfor %}
{%- endif %}
{%- if 'acls' in frontend[1] %}
{%- for acl in frontend[1].acls %}
acl {{ acl }}
2015-05-23 13:43:21 -04:00
{%- endfor %}
{%- endif %}
{%- if 'reqadd' in frontend[1] %}
{%- for reqadd in frontend[1].reqadd %}
reqadd {{ reqadd }}
2015-05-23 13:43:21 -04:00
{%- endfor %}
{%- endif %}
default_backend {{ frontend[1].default_backend }}
2015-05-23 13:43:21 -04:00
{%-if 'use_backends' in frontend[1] -%}
{%- for use_backend in frontend[1].use_backends %}
use_backend {{ use_backend }}
2015-05-23 13:43:21 -04:00
{% endfor %}
{%- endif %}
{% endfor %}
{%- endif %}
#---------------------------------------------------------------------
# backend instances
#---------------------------------------------------------------------
{%- if 'backends' in salt['pillar.get']('haproxy', {}) %}
2015-05-23 13:43:21 -04:00
{%- for backend in salt['pillar.get']('haproxy:backends', {}).iteritems() %} # Backend loop start
backend {{ backend[1].get(name, backend[0]) }}
2015-05-23 13:43:21 -04:00
{%- if 'redirects' in backend[1] %}
{%- for redirect in backend[1].redirects %} # Redirect loop start
redirect {{ redirect }}{% endfor %}
2015-05-23 13:43:21 -04:00
{%- endif %}
{%- if 'balance' in backend[1] %}
balance {{ backend[1].balance }}
{%- endif %}
2015-05-23 13:43:21 -04:00
{%- if 'options' in backend[1] %}
{%- for option in backend[1].options %}
option {{ option }}
{%- endfor %}
2015-05-23 13:43:21 -04:00
{%- endif %}
{%- if 'cookie' in backend[1] %}
cookie {{ backend[1].cookie }}
2015-05-23 13:43:21 -04:00
{%- endif %}
{%- if 'stats' in backend[1] %}
{%- for option, value in backend[1].stats.iteritems() %}
2015-05-23 13:43:21 -04:00
{%- if option == 'enable' and value %}
stats enable
2015-05-23 13:43:21 -04:00
{%- else %}
stats {{ option }} {{ value }}
2015-05-23 13:43:21 -04:00
{%- endif %}
{%- endfor %}
2015-05-23 13:43:21 -04:00
{%- endif %}
2015-07-17 23:36:15 -04:00
{f 'defaultserver' in listener[1] %}
default-server {% for option, value in listener[1].defaultserver.iteritems() -%} {{ ' '.join((option,value|string)) }} {%- endfor %}
{% endif %}%- endif %}
2015-05-23 13:43:21 -04:00
{%- if 'servers' in backend[1] %}
{%- for server in backend[1].servers.iteritems() %}
server {{ server[1].get(name,server[0]) }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }}{% endfor %}
2015-05-23 13:43:21 -04:00
{% endif %}
{% endfor %} # Backend loop end
{% endif %}