From 5da10f8559a04fc69e55a086b7c606e8b256298c Mon Sep 17 00:00:00 2001 From: Daniel 'f0o' Preussker Date: Tue, 8 Apr 2025 11:17:51 +0000 Subject: [PATCH] Add custom errorfiles Change-Id: Ifc4feeffc951ec03745bf65d51db5e4917f1be29 --- defaults/main.yml | 29 +++++++++++++++++++ ...xy_custom_errorfiles-500674edcaa6cbb6.yaml | 5 ++++ templates/haproxy.cfg.j2 | 3 ++ 3 files changed, 37 insertions(+) create mode 100644 releasenotes/notes/haproxy_custom_errorfiles-500674edcaa6cbb6.yaml diff --git a/defaults/main.yml b/defaults/main.yml index 923965c..9db5358 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -330,3 +330,32 @@ haproxy_static_files_extra: [] haproxy_static_files: "{{ haproxy_static_files_default + haproxy_static_files_extra }}" haproxy_sysctl_file: "{{ openstack_sysctl_file | default('/etc/sysctl.conf') }}" + +# Allows to define custom errorfiles in the format: +# - code: 504 +# path: /path/to/504.http +# You can use haproxy_static_files_extra to add those files. +# See https://github.com/haproxy/haproxy/tree/master/examples/errorfiles for examples +# +# An example combination of haproxy_static_files_extra and haproxy_errorfiles: +# haproxy_static_files_extra: +# - dest: /etc/haproxy/500.http +# content: | +# HTTP/1.0 500 Internal Server Error +# Cache-Control: no-cache +# Connection: close +# Content-Type: text/html +# +#

500 Internal Server Error

+# This Server Made a Boo Boo +# +# - dest: /etc/haproxy/504.http +# content: "{{ lookup('file', '/etc/openstack_deploy/haproxy/504.http') }}" +# +# haproxy_errorfiles: +# - code: 500 +# path: /etc/haproxy/500.http +# - code: 504 +# path: /etc/haproxy/504.http +# +haproxy_errorfiles: [] diff --git a/releasenotes/notes/haproxy_custom_errorfiles-500674edcaa6cbb6.yaml b/releasenotes/notes/haproxy_custom_errorfiles-500674edcaa6cbb6.yaml new file mode 100644 index 0000000..d0562c6 --- /dev/null +++ b/releasenotes/notes/haproxy_custom_errorfiles-500674edcaa6cbb6.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added support for defining custom error files using haproxy_errorfiles. + These files can be distributed alongside haproxy_static_files_extra. diff --git a/templates/haproxy.cfg.j2 b/templates/haproxy.cfg.j2 index 7c6f81e..3e70791 100644 --- a/templates/haproxy.cfg.j2 +++ b/templates/haproxy.cfg.j2 @@ -36,6 +36,9 @@ defaults timeout http-request {{ haproxy_http_request_timeout }} timeout server {{ haproxy_server_timeout }} maxconn {{ haproxy_maxconn }} +{% for value in haproxy_errorfiles %} + errorfile {{ value.code }} {{ value.path }} +{% endfor %} {% if haproxy_stats_enabled | bool %} {% set haproxy_ssl_path = haproxy_ssl_cert_path + "/haproxy_" + (haproxy_host | default(ansible_facts['hostname'])) + "-" + ((haproxy_bind_internal_lb_vip_interface is truthy) | ternary(haproxy_bind_internal_lb_vip_address ~ '-' ~ haproxy_bind_internal_lb_vip_interface, haproxy_bind_internal_lb_vip_address)) + ".pem" %} listen stats