From 8b21a0a0ee010a18a34c00aeab5edbfc72f3d7a6 Mon Sep 17 00:00:00 2001 From: Adam Hamsik Date: Thu, 25 Oct 2018 16:43:14 +0200 Subject: [PATCH] Add ability to define default_server option --- README.md | 3 +++ defaults/main.yml | 1 + templates/etc/haproxy/backend.cfg.j2 | 4 ++++ templates/etc/haproxy/defaults.cfg.j2 | 4 ++++ templates/etc/haproxy/listen.cfg.j2 | 4 ++++ 5 files changed, 16 insertions(+) diff --git a/README.md b/README.md index b10f39ba..e6edf927 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ Set up (the latest version of) [HAProxy](http://www.haproxy.org/) in Ubuntu syst * `haproxy_defaults_compression`: [optional]: Compression declarations * `haproxy_defaults_compression.{}.name`: [required]: The compression name (e.g. `algo`, `type`, `offload`) * `haproxy_defaults_compression.{}.value`: [required]: The compression value, (e.g. if name = algo : one of this values `identity`, `gzip`, `deflate`, `raw-deflate` / if name = type : list of mime type separated by space for example `text/html text/plain text/css` / if name = `offload` value is empty) +* `haproxy_default_server_params`: [optional]: Default server backend parameters passed to each backend/listen server. * `haproxy_ssl_map`: [default: `[]`]: SSL declarations * `haproxy_ssl_map.{n}.src`: The local path of the file to copy, can be absolute or relative (e.g. `../../../files/haproxy/etc/haproxy/ssl/star-example-com.pem`) @@ -155,6 +156,7 @@ Set up (the latest version of) [HAProxy](http://www.haproxy.org/) in Ubuntu syst * `haproxy_listen.{n}.errorfile`: [optional]: Errorfile declarations * `haproxy_listen.{n}.errorfile.{n}.code`: [required]: The HTTP status code. Currently, HAProxy is capable of generating codes 200, 400, 403, 408, 500, 502, 503, and 504 (e.g. `400`) * `haproxy_listen.{n}.errorfile.{n}.file`: [required]: A file containing the full HTTP response (e.g `/etc/haproxy/errors/400.http`) +* `haproxy_listen.{n}.default_server_params`: [optional]: Default server params applied for each server for this particular listen entry. * `haproxy_frontend`: [default: `[]`]: Front-end declarations * `haproxy_frontend.{n}.name`: [required]: The name of the section (e.g. `https`) @@ -279,6 +281,7 @@ Set up (the latest version of) [HAProxy](http://www.haproxy.org/) in Ubuntu syst * `haproxy_backend.{n}.errorfile`: [optional]: Errorfile declarations * `haproxy_backend.{n}.errorfile.{n}.code`: [required]: The HTTP status code. Currently, HAProxy is capable of generating codes 200, 400, 403, 408, 500, 502, 503, and 504 (e.g. `400`) * `haproxy_backend.{n}.errorfile.{n}.file`: [required]: A file containing the full HTTP response (e.g `/etc/haproxy/errors/400.http`) +* `haproxy_backend.{n}.default_server_params`: [optional]: Default server params applied for each server for this particular backend entry. * `haproxy_userlists`: [default: `[]`]: Userlist declarations * `haproxy_userlists.{n}.name`: [required]: The name of the userlist diff --git a/defaults/main.yml b/defaults/main.yml index 24b3852a..ddd448e7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -40,6 +40,7 @@ haproxy_defaults_mode: http haproxy_defaults_option: - httplog - dontlognull +haproxy_default_server_params: [] haproxy_defaults_timeout: - type: connect timeout: 5000 diff --git a/templates/etc/haproxy/backend.cfg.j2 b/templates/etc/haproxy/backend.cfg.j2 index 5d20da34..7dd0e660 100644 --- a/templates/etc/haproxy/backend.cfg.j2 +++ b/templates/etc/haproxy/backend.cfg.j2 @@ -106,6 +106,10 @@ backend {{ backend.name }} compression {{ compression.name }} {{ compression.value }} {% endfor %} +{% if backend.default_server_params is defined %} + default-server {% for param in backend.default_server_params | default([]) %} {{ param }}{% endfor %} +{% endif %} + {% for server in backend.server | default([]) %} server {{ server.name }} {{ server.listen }}{% for param in server.param | default([]) %} {{ param }}{% endfor %} diff --git a/templates/etc/haproxy/defaults.cfg.j2 b/templates/etc/haproxy/defaults.cfg.j2 index 6a2f95ec..9473e075 100644 --- a/templates/etc/haproxy/defaults.cfg.j2 +++ b/templates/etc/haproxy/defaults.cfg.j2 @@ -39,3 +39,7 @@ {% for compression in haproxy_defaults_compression | default([]) %} compression {{ compression.name }} {{ compression.value }} {% endfor %} + +{% if haproxy_default_server_params is defined %} + default-server {% for param in haproxy_default_server_params | default([]) %} {{ param }}{% endfor %} +{% endif %} \ No newline at end of file diff --git a/templates/etc/haproxy/listen.cfg.j2 b/templates/etc/haproxy/listen.cfg.j2 index 950ab97d..18328c25 100644 --- a/templates/etc/haproxy/listen.cfg.j2 +++ b/templates/etc/haproxy/listen.cfg.j2 @@ -138,6 +138,10 @@ listen {{ listen.name }} compression {{ compression.name }} {{ compression.value }} {% endfor %} +{% if listen.default_server_params is defined %} + default-server {% for param in listen.default_server_params | default([]) %} {{ param }}{% endfor %} +{% endif %} + {% for server in listen.server | default([]) %} server {{ server.name }} {{ server.listen }}{% for param in server.param | default([]) %} {{ param }}{% endfor %}