updated haproxy state

This commit is contained in:
Paul 2022-11-13 20:48:27 +01:00
parent 954e8cf7bf
commit 039abe0b52
2 changed files with 24 additions and 15 deletions

View File

@ -28,6 +28,8 @@ haproxy:
timeout connect: 4s
timeout server: 30m
timeout check: 5s
balance: roundrobin
check: True
dir: /etc/haproxy
configfile: haproxy.cfg
user: haproxy
@ -65,7 +67,7 @@ haproxy:
- text/plain
- text/css
- text/javascript
- application/javascript
- application/json
cache_file_types:
- .css
- .js

View File

@ -14,9 +14,18 @@
http-response set-header server "{{ haproxy.config.servername }}"
{%- endmacro -%}
{%- macro endpoints(servers, check, ssl) -%}
{%- macro httpcheckrules(layer="layer7",inter="2s",fall=5,rise=5) -%}check observe {{ layer }} inter {{ inter }} fall {{ fall }} rise {{ rise }}{%- endmacro -%}
{%- macro httpsslrules() -%}ssl verify none{%- endmacro -%}
{%- macro httpendpoints(servers=[], check=True, ssl=False) -%}
{%- for server in servers %}
server {{ server.name }} {{ server.name }}:{{ server.port }}{{ " check observe layer7 inter 2s fall 5 rise 5 " if check|default(true) }}{{ " ssl verify none " if ssl|default(false) }}
server {{ server.name }} {{ server.name }}:{{ server.port }}{{ " " + httpcheckrules() if check }}{{ " " + httpsslrules() if ssl }}
{%- endfor %}
{%- endmacro -%}
{%- macro tcpendpoints(servers=[], check=True) -%}
{%- for server in servers %}
server {{ server.name }} {{ server.name }}:{{ server.port }}{{ " check" if check }}{{ " backup" if server.backup|default(False) }} port {{ server.port }}
{%- endfor %}
{%- endmacro -%}
@ -116,37 +125,37 @@ frontend https
# HTTP Backends
{% for name, values in haproxy.config.vhosts.items() %}
{%- if not values.redirect|default(false) %}
{%- if not values.redirect|default(False) %}
backend {{ name }}
balance {{ values.balance|default("roundrobin") }}
balance {{ values.balance|default(haproxy.config.balance) }}
mode http
option forwardfor
{%- if values.check|default(false) %}
{%- if values.check|default(haproxy.config.check) %}
option httpchk
{%- for step in values.check_steps|default([]) %}
http-check {{ step }}
{%- endfor %}
{%- endif %}
{%- if values.head|default(false) %}
{%- if values.head|default(False) %}
{{ head() }}
{%- endif %}
{%- if values.compression|default(true) %}
{%- if values.compression|default(True) %}
{{ compression() }}
{%- endif %}
{%- if values.usecache|default(true) %}
{%- if values.usecache|default(True) %}
{{ cache() }}
{%- endif %}
{%- if values.serverheader|default(true) %}
{%- if values.serverheader|default(True) %}
{{ serverheader() }}
{%- endif %}
{%- if values.internal|default(false) %}
{%- if values.internal|default(False) %}
{{ internal() }}
{%- endif %}
{{- endpoints(values.servers, values.check, values.ssl) }}
{{- httpendpoints(servers=values.servers, check=values.check|default(haproxy.config.check), ssl=values.ssl|default(False)) }}
{%- endif %}
{% endfor %}
@ -160,7 +169,5 @@ listen {{ name }}
option pgsql-check user postgres
{%- endif %}
default-server inter 3s fall 3
{%- for server in values.servers %}
server {{ server.name }} {{ server.name }}:{{ server.port }} check {{ "backup" if server.backup|default(false) }} port {{ server.port }}
{%- endfor %}
{{- tcpendpoints(servers=values.servers, check=values.check|default(haproxy.config.check)) }}
{% endfor -%}