Skip to content
Snippets Groups Projects
Verified Commit fb29bff2 authored by Nicolas Lenz's avatar Nicolas Lenz :snowflake:
Browse files

feat: add support for http-errors section

parent fe432300
No related branches found
No related tags found
1 merge request!21Add http-errors
Pipeline #203378 passed
...@@ -35,6 +35,9 @@ Role Variables ...@@ -35,6 +35,9 @@ Role Variables
* `haproxy_listen` * `haproxy_listen`
A list of listen proxies. A list of listen proxies.
* `haproxy_http_errors`
A list of http-errors sections containing errorfiles for various status codes.
Here is a complete list of variables: Here is a complete list of variables:
``` ```
......
...@@ -102,6 +102,56 @@ ...@@ -102,6 +102,56 @@
loop: "{{ haproxy_backends }}" loop: "{{ haproxy_backends }}"
when: haproxy_backends is defined when: haproxy_backends is defined
## ASSEMBLE CONFIG - HTTP-ERRORS
- name: Create directory for the error files
ansible.builtin.file:
path: "{{ haproxy_config_dir }}/custom_errors"
state: directory
owner: root
group: root
mode: "0755"
- name: Copy error pages
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ haproxy_config_dir }}/custom_errors"
mode: "0644"
with_fileglob:
- "{{ inventory_hostname }}/custom_errors/*"
- name: 'Create directory for the http-errors'
ansible.builtin.file:
path: "{{ haproxy_config_dir }}/http-errors.d"
state: directory
owner: root
group: root
mode: "0755"
- name: "List files for the http-errors"
ansible.builtin.find:
paths: "{{ haproxy_config_dir }}/http-errors.d"
patterns: "*.cfg"
register: directory_contents
changed_when: false
- name: "Remove unmanaged files for the http-errors"
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
when: (item.path | basename) not in (haproxy_http_errors | json_query('[*].name') | map('regex_replace', '(^.*$)', '\\1.cfg') | list)
loop: "{{ directory_contents.files }}"
- name: 'Build up the http-errors'
ansible.builtin.template:
src: "http-errors.cfg"
dest: "{{ haproxy_config_dir }}/http-errors.d/{{ item.name }}.cfg"
owner: root
group: root
mode: "0644"
loop: "{{ haproxy_http_errors }}"
when: haproxy_http_errors is defined
## ASSEMBLE CONFIG - LISTEN ## ASSEMBLE CONFIG - LISTEN
- name: 'Create directory for the listen sections' - name: 'Create directory for the listen sections'
...@@ -239,6 +289,14 @@ ...@@ -239,6 +289,14 @@
group: root group: root
mode: "0644" mode: "0644"
- name: 'Assemble the http-errors configuration file'
ansible.builtin.assemble:
src: "{{ haproxy_config_dir }}/http-errors.d"
dest: "{{ haproxy_config_dir }}/compiled/07-http-errors.cfg"
owner: root
group: root
mode: "0644"
- name: 'Assemble the final configuration file' - name: 'Assemble the final configuration file'
ansible.builtin.assemble: ansible.builtin.assemble:
src: "{{ haproxy_config_dir }}/compiled" src: "{{ haproxy_config_dir }}/compiled"
......
...@@ -113,3 +113,7 @@ frontend {{ item.name }} {%if item.ip is defined %}{{ item.ip }}{% endif %}{%if ...@@ -113,3 +113,7 @@ frontend {{ item.name }} {%if item.ip is defined %}{{ item.ip }}{% endif %}{%if
use_backend {{ backend.name }} {{ backend.condition }} use_backend {{ backend.name }} {{ backend.condition }}
{% endfor -%} {% endfor -%}
{% endif -%} {% endif -%}
{%- if item.errorfiles is defined -%}
errorfiles {{ item.errorfiles }}
{% endif %}
{%- import '_macros.j2' as macros with context -%}
#{{ ansible_managed }}
http-errors {{ item.name }}
{% if item.errorfiles is defined %}
{%- for errorfile in item.errorfiles -%}
errorfile {{ errorfile.status }} {{ errorfile.file }}
{% endfor -%}
{% endif -%}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment