From b224c6843eff242b8ce3df121be58a9fe85c77f9 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Tue, 10 Oct 2023 09:07:44 +0200 Subject: [PATCH] updated haproxy state --- states/haproxy/templates/haproxy.cfg.j2 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/states/haproxy/templates/haproxy.cfg.j2 b/states/haproxy/templates/haproxy.cfg.j2 index d74c08a..e014177 100644 --- a/states/haproxy/templates/haproxy.cfg.j2 +++ b/states/haproxy/templates/haproxy.cfg.j2 @@ -23,6 +23,7 @@ http-response return status 404 content-type text/html string "

404 not found {%- macro httpsslrules(h2=False) -%}ssl verify none{{ " alpn h2,http/1.1" if h2 }}{%- endmacro -%} {%- macro httpendpoints(servers=[], check=True, disabled=False) -%} + {%- if servers -%} {%- for server in servers %} {% if server.name in haproxy.servers.keys() -%} {%- set addr = haproxy.servers[server.name][0] -%} @@ -31,9 +32,11 @@ http-response return status 404 content-type text/html string "

404 not found {%- endif -%} server {{ server.name }} {{ addr }}:{{ server.port }}{{ " " + httpcheckrules(inter=server.inter|default("1s"), fall=server.fall|default(5), rise=server.rise|default(5)) if check }}{{ " " + httpsslrules(server.h2|default(False)) if server.ssl|default(False) }}{{ " disabled" if server.disabled|default(False) }}{{ " send-proxy" if server.proxy|default(False) }}{{ " on-marked-down shutdown-sessions on-marked-up shutdown-backup-sessions" if server.killsessions|default(False) }} {%- endfor %} + {%- endif -%} {%- endmacro -%} {%- macro tcpendpoints(servers=[], check=True) -%} + {%- if servers -%} {%- for server in servers %} {% if server.name in haproxy.servers.keys() -%} {%- set addr = haproxy.servers[server.name][0] -%} @@ -42,6 +45,7 @@ http-response return status 404 content-type text/html string "

404 not found {%- endif -%} server {{ server.name }} {{ addr }}:{{ server.port }}{{ " check" if check }}{{ " backup" if server.backup|default(False) }} port {{ server.port }}{{ " on-marked-down shutdown-sessions on-marked-up shutdown-backup-sessions" if server.killsessions|default(False) }} {%- endfor %} + {%- endif -%} {%- endmacro -%} {%- macro cache() -%} @@ -270,7 +274,7 @@ backend {{ name }} from {{ haproxy.config.namespace }} {%- if values.internal|default(False) %} {{ internal() }} {%- endif %} - {{- httpendpoints(servers=values.servers, check=values.check|default(haproxy.config.check)) }} + {{- httpendpoints(servers=values.servers|default([]), check=values.check|default(haproxy.config.check)) }} {%- endif %} {% endfor %} @@ -290,7 +294,7 @@ listen {{ name }} from {{ haproxy.config.namespace }} option spop-check {%- endif %} default-server inter 1s fall 5 - {{- tcpendpoints(servers=values.servers, check=values.check|default(haproxy.config.check)) }} + {{- tcpendpoints(servers=values.servers|default([]), check=values.check|default(haproxy.config.check)) }} {% endfor %} # SPOE Agents