From 41ddfd351f8551a4bb09f0427551fca1cf9ba115 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Wed, 29 Apr 2020 13:55:31 +1000 Subject: [PATCH 1/2] add headins tidy the config file once generated to make it human friendly --- tasks/configuration.yml | 12 ++++++++++++ templates/etc/haproxy/haproxy.cfg.j2 | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tasks/configuration.yml b/tasks/configuration.yml index b1fb1f01..4d31954e 100644 --- a/tasks/configuration.yml +++ b/tasks/configuration.yml @@ -11,3 +11,15 @@ notify: restart haproxy tags: - haproxy-configuration-update-file + +- name: configuration | format file (remove empty) + lineinfile: + path: /etc/haproxy/haproxy.cfg + regex: '^\n' + state: absent + +- name: configuration | format file (empty before headings) + replace: + dest: /etc/haproxy/haproxy.cfg + regexp: "^#--#" + replace: "" diff --git a/templates/etc/haproxy/haproxy.cfg.j2 b/templates/etc/haproxy/haproxy.cfg.j2 index f291e05d..bd3d7a0d 100644 --- a/templates/etc/haproxy/haproxy.cfg.j2 +++ b/templates/etc/haproxy/haproxy.cfg.j2 @@ -1,17 +1,30 @@ # {{ ansible_managed }} - +#--# +# Global global {% include 'global.cfg.j2' %} +#--# +# Defaults defaults {% include 'defaults.cfg.j2' %} +#--# +# Userlist {% include 'userlist.cfg.j2' %} +#--# +# Resolvers {% include 'resolvers.cfg.j2' %} +#--# +# Listen {% include 'listen.cfg.j2' %} +#--# +# Frontend {% include 'frontend.cfg.j2' %} +#--# +# Backend {% include 'backend.cfg.j2' %} From 68b9055e6a9b2d8a05fcc0baad26b0eae1b103a9 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Wed, 29 Apr 2020 13:57:41 +1000 Subject: [PATCH 2/2] allow no backend mode if status exists --- templates/etc/haproxy/backend.cfg.j2 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/etc/haproxy/backend.cfg.j2 b/templates/etc/haproxy/backend.cfg.j2 index b1b60f0d..f9243737 100644 --- a/templates/etc/haproxy/backend.cfg.j2 +++ b/templates/etc/haproxy/backend.cfg.j2 @@ -8,9 +8,11 @@ backend {{ backend.name }} bind-process {{ backend.bind_process | join(' ') }} {% endif %} +{% if backend.mode is not defined and backend.stats is defined %} +{% else %} mode {{ backend.mode }} - - balance {{ backend.balance }} + balance {{ backend.balance | default('roundrobin') }} +{% endif %} {% if backend.source is defined %} source {{ backend.source }}