Skip to content

Commit

Permalink
Merge pull request #109 from floored1585/dynamic_backends
Browse files Browse the repository at this point in the history
Dynamic backends
  • Loading branch information
tersmitten authored Sep 25, 2020
2 parents d50e372 + 9714d52 commit 5295109
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ Set up (the latest version of) [HAProxy](http://www.haproxy.org/) in Ubuntu syst
* `haproxy_backend.{n}.server_template.fqdn`: [required]: A FQDN for all the servers this template initializes
* `haproxy_backend.{n}.server_template.port`: [optional]: Port specification
* `haproxy_backend.{n}.server_template.{n}.param`: [optional]: A list of parameters for this server template
* `haproxy_backend.{n}.server_dynamic`: [optional]: Dynamic backend server declaration
* `haproxy_backend.{n}.server_dynamic.{n}.group`: [required]: An ansible group containing hosts to be added as backend servers. Uses `inventory_hostname` for name and either `ansible_host` (if defined) or `inventory_hostname` for the listen address of each host.
* `haproxy_backend.{n}.server_dynamic.{n}.listen_port`: [optional]: The port to use with each dynamic backend (translates to `listen <ansible_host/inventory_hostname>:<listen_port>`).
* `haproxy_backend.{n}.server_dynamic.{n}.param`: [optional]: A list of parameters to apply on each backend server.
* `haproxy_backend.{n}.retry_on`: [optional, default `[]`]: Specify when to attempt to automatically retry a failed request. Provide a list of keywords or HTTP status codes, each representing a type of failure event on which an attempt to retry the request is desired. For details, see HAProxy documentation.
* `haproxy_backend.{n}.retries`: [optional]: Number of retries to perform on a server after a connection failure

Expand Down
7 changes: 7 additions & 0 deletions templates/etc/haproxy/backend.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ backend {{ backend.name }}
{% for server in backend.server | default([]) %}
server {{ server.name }} {{ server.listen }}{% for param in server.param | default([]) %} {{ param }}{% endfor %}

{% endfor %}
{% for server_dynamic in backend.server_dynamic | default([]) %}
{% for server_name in groups[server_dynamic.group] %}
{% set server = hostvars[server_name] %}
server {{ server.inventory_hostname }} {% if server.ansible_host is defined %}{{ server.ansible_host }}{% else %}{{ server_name }}{% endif %}{% if server_dynamic.listen_port is defined %}:{{ server_dynamic.listen_port }}{% endif %}{% for param in server_dynamic.param | default([]) %} {{ param }}{% endfor %}

{% endfor %}
{% endfor %}
{% if backend.server_template is defined %}
server-template {{ backend.server_template.name }} {{ backend.server_template.num}} {{ backend.server_template.fqdn }}{% if backend.server_template.port is defined %}:{{ backend.server_template.port }}{% endif %} {% for param in backend.server_template.param | default([]) %} {{ param }}{% endfor %}
Expand Down

0 comments on commit 5295109

Please sign in to comment.