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/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 }} 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' %}