diff --git a/states/haproxy/defaults.yaml b/states/haproxy/defaults.yaml index 2302ec4..a0ca73d 100644 --- a/states/haproxy/defaults.yaml +++ b/states/haproxy/defaults.yaml @@ -31,7 +31,7 @@ haproxy: countries: FR: OK dbs: - - name: /var/lib/haproxy/geoip/GeoLite2-City.mmdb + GeoLite2-City.mmdb: url: https://git.paulbsd.com/paulbsd/GeoLite.mmdb/releases/download/2023.03.26/GeoLite2-City.mmdb lua_max_mem: 1024 peers: @@ -44,25 +44,29 @@ haproxy: - scripts - mods - errors - geoip_dbs: scripts: - - name: mods/haproxy.c + haproxy: + path: mods/haproxy.c lib: true - - name: scripts/compile.lua + compile: + path: scripts/compile.lua lib: true - - name: scripts/geoip.lua + geoip: + path: scripts/geoip.lua lib: false args: - /var/lib/haproxy/geoip/GeoLite2-City.mmdb - - name: scripts/json.lua + json: + path: scripts/json.lua lib: true - - name: scripts/collector.lua + scripts/collector.lua: lib: false #- name: scripts/weight.lua # lib: false # args: # - 5 - - name: scripts/state.lua + state: + path: scripts/state.lua lib: false args: - 30 diff --git a/states/haproxy/install.sls b/states/haproxy/install.sls index 03df9b2..5481288 100644 --- a/states/haproxy/install.sls +++ b/states/haproxy/install.sls @@ -25,11 +25,11 @@ haproxy-config-{{ dir }}-dir: - mode: "0700" {% endfor %} -{% for file in haproxy.config.scripts %} -haproxy-script-{{ file.name }}: +{% for script, params in haproxy.config.scripts.items() %} +haproxy-script-{{ script }}: file.managed: - - name: {{ haproxy.config.dir }}/{{ file.name }} - - source: salt://haproxy/{{ file.name }} + - name: {{ haproxy.config.dir }}/{{ params.path }} + - source: salt://haproxy/{{ params.path }} - user: {{ haproxy.config.user }} - group: {{ haproxy.config.group }} - mode: "0600" @@ -37,11 +37,11 @@ haproxy-script-{{ file.name }}: - service: haproxy-service {% endfor %} -{% for file in haproxy.config.geoip.dbs %} -haproxy-geoip-{{ file.name }}: +{% for dbname, params in haproxy.config.geoip.dbs.items() %} +haproxy-geoip-{{ dbname }}: file.managed: - - name: {{ file.name }} - - source: {{ file.url }} + - name: /var/lib/haproxy/geoip/{{ dbname }} + - source: {{ params.url }} - skip_verify: True - makedirs: True - user: {{ haproxy.config.user }} diff --git a/states/haproxy/templates/haproxy.cfg.j2 b/states/haproxy/templates/haproxy.cfg.j2 index d7b8caf..9edb017 100644 --- a/states/haproxy/templates/haproxy.cfg.j2 +++ b/states/haproxy/templates/haproxy.cfg.j2 @@ -95,9 +95,9 @@ global maxconn 1000 lua-prepend-path {{ haproxy.config.dir }}/mods/?.so cpath lua-prepend-path {{ haproxy.config.dir }}/scripts/?.lua -{%- for script in haproxy.config.scripts %} - {%- if not script.lib and script.enabled|default(true) %} - lua-load {{ haproxy.config.dir }}/{{ script.name }} {% if "args" in script.keys() %}{{ script.args|join(" ") }}{% endif %} +{%- for script,params in haproxy.config.scripts.items() %} + {%- if not params.lib and params.enabled|default(true) %} + lua-load {{ haproxy.config.dir }}/{{ params.path }} {% if "args" in params.keys() %}{{ params.args|join(" ") }}{% endif %} {%- endif %} {%- endfor %} {%- if haproxy.config.api.enable %} @@ -173,7 +173,7 @@ frontend fe_http from {{ haproxy.config.namespace }} http-request return status 200 content-type text/html lf-string "host: %H\ndate: %[var(txn.httpdate)]\nsrchash: %[var(txn.srchash)]\n" if self_host path_info {%- if haproxy.config.geoip.enabled %} - # GeoIP + ## GeoIP {{ geoip() }} {%- endif %} @@ -230,7 +230,7 @@ frontend fe_https from {{ haproxy.config.namespace }} http-request deny deny_status 429 if max_req_rate !internal {%- if haproxy.config.geoip.enabled %} - # GeoIP + ## GeoIP {{ geoip() }} {%- endif %}