Dealing with multiple backends
michalmedvecky opened this issue · 3 comments
michalmedvecky commented
Hello
thank you for this comprehensive role.
I see in examples that you need to list all backends by hand in vars. What if I have dynamic inventory and want to add backends dynamically? Do you have some clever solution for this?
Thanks
tersmitten commented
Let me think about it. I'll get back to you.
michalmedvecky commented
I ended up with
{% for server in groups["all"] %}
{% if server in groups[backend.name] | default("") %}
server {{ server }} {{ hostvars[server].ansible_ssh_host }}:{{ haproxy_backend.0.server.0.port }}{% for param in haproxy_backend.0.server.0.param | default([]) %} {{ param }}{% endfor %}
{% endif %}
{% endfor %}
in templates/etc/haproxy/backend.cfg.j2
I am not very happy about haproxy_backend.0.server.0.param
, which I ignore in latter:
{% for server in backend.server | default([])%}
{% if server.name != "default" %}
server {{ server.name }} {{ server.listen }}{% for param in server.param | default([]) %} {{ param }}{% endfor %}
{% endif %}
{% endfor %}
But works for me now.
tersmitten commented
Closing this due to inactivity