From 00c68173c93f62bdadb935107122f14b4eb942aa Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sat, 13 Jul 2024 22:00:05 +0200 Subject: [PATCH] updated haproxy state --- states/haproxy/map.jinja | 1 + states/haproxy/templates/haproxy.cfg.j2 | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/states/haproxy/map.jinja b/states/haproxy/map.jinja index 8b6a766..1feb7c7 100644 --- a/states/haproxy/map.jinja +++ b/states/haproxy/map.jinja @@ -7,6 +7,7 @@ {%- set users = salt['pillar.get']('htpasswds') -%} {%- set net = salt['pillar.get']('net') -%} {%- set fqdn = salt['grains.get']('fqdn') -%} +{%- set country = salt['grains.get']('country') -%} {% set peers_ip = [] %} {%- for k,v in haproxy.peers.items() %} diff --git a/states/haproxy/templates/haproxy.cfg.j2 b/states/haproxy/templates/haproxy.cfg.j2 index d350d46..1b7acd4 100644 --- a/states/haproxy/templates/haproxy.cfg.j2 +++ b/states/haproxy/templates/haproxy.cfg.j2 @@ -1,5 +1,5 @@ ## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }} -{%- from "haproxy/map.jinja" import haproxy,certs,fqdn with context %} +{%- from "haproxy/map.jinja" import haproxy,fqdn,country with context %} {%- set ns = namespace(default_backend='notdefined') %} {%- for name, values in haproxy.config.vhosts.items() %}{% if values.default_backend|default(false) %}{% set ns.default_backend = name %}{% endif %}{% endfor %} @@ -93,6 +93,7 @@ global server-state-file /var/run/haproxy.state mworker-max-reloads 2 maxconn 1000 + set-var proc.country str('{{ country }}') lua-prepend-path {{ haproxy.config.dir }}/mods/?.so cpath lua-prepend-path {{ haproxy.config.dir }}/scripts/?.lua {%- for script,params in haproxy.config.scripts.items() %} @@ -175,7 +176,7 @@ frontend fe_http from {{ haproxy.config.namespace }} ## Returns http-request return status 200 content-type text/plain string "User-agent: *\r\nAllow: /" if robots_txt http-request return status 200 content-type text/plain string "Contact: mailto:{{ haproxy.config.syscontact }}" if security_txt - http-request return status 200 content-type "text/html; charset=utf-8" lf-string "host: %H
date: %[var(txn.httpdate)]
src: %[var(req.src)]
srchash: %[var(txn.srchash)]" if self_host path_info + http-request return status 200 content-type "text/html; charset=utf-8" lf-string "host: %H
country: %[var(proc.country)]
date: %[var(txn.httpdate)]
src: %[var(req.src)]
srchash: %[var(txn.srchash)]" if self_host path_info {%- if haproxy.config.geoip.enabled %} ## GeoIP @@ -244,7 +245,7 @@ frontend fe_https from {{ haproxy.config.namespace }} ## Returns http-request return status 200 content-type text/plain string "User-agent: *\r\nAllow: /" if robots_txt http-request return status 200 content-type text/plain string "Contact: mailto:{{ haproxy.config.syscontact }}" if security_txt - http-request return status 200 content-type "text/html; charset=utf-8" lf-string "host: %H
date: %[var(txn.httpdate)]
src: %[var(req.src)]
srchash: %[var(txn.srchash)]" if self_host path_info + http-request return status 200 content-type "text/html; charset=utf-8" lf-string "host: %H
country: %[var(proc.country)]
date: %[var(txn.httpdate)]
src: %[var(req.src)]
srchash: %[var(txn.srchash)]" if self_host path_info ## Headers http-request set-header X-Proxy-Id "%H"